2.1 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| style-tag-registry-get | api | formatter | 20260613 | Look up one style tag from a StyleTagRegistry. |
|
Style-tag-registry-get
Look up one named style tag from a StyleTagRegistry. This is the direct inspection helper for tests, setup validation, or custom formatter logic that needs the stored TextStyle value.
Interface
pub fn StyleTagRegistry::get(self : StyleTagRegistry, name : String) -> TextStyle? {
input
self : StyleTagRegistry- Registry to inspect.name : String- Tag name to look up.
output
TextStyle?-Some(style)when the tag exists, otherwiseNone.
Explanation
Detailed rules explaining key parameters and behaviors
- The tag name is normalized before lookup.
- This method only checks the current registry value passed as
self. - Missing names return
Noneinstead of raising an error. - This is useful when code needs the style value itself rather than only presence or absence.
How to Use
Here are some specific examples provided.
When Need To Inspect A Custom Tag
When setup code or tests should verify that a tag was stored:
let tags = style_tag_registry().set_tag("accent", fg=Some("#4cc9f0"))
match tags.get("accent") {
Some(style) => ignore(style)
None => panic()
}
In this example, the registry returns the stored TextStyle for the tag.
When Need Graceful Missing-tag Handling
When code should tolerate an absent entry:
let tags = style_tag_registry()
let maybe_style = tags.get("missing")
In this example, maybe_style becomes None instead of failing.
Error Case
e.g.:
-
There is no separate failure path for a missing tag; the method returns
None. -
If code only needs a yes-or-no existence check,
contains(...)is simpler than reading the optional style value.
Notes
-
Use this method when callers need the stored
TextStyleitself. -
This lookup does not automatically fall back to the global registry or builtin tags.