pub struct Tag {
pub handle: String,
pub suffix: String,
pub original_handle: String,
}Expand description
A YAML tag.
Fields§
§handle: StringResolved tag handle or prefix.
Examples include tag:yaml.org,2002: for core-schema tags and ! for local tags.
suffix: StringTag suffix following the resolved handle or prefix.
original_handle: StringTag handle as written in the source before %TAG directive resolution.
For example, with %TAG !e! tag:example.com,2000:, a source tag !e!keep is resolved
as handle = "tag:example.com,2000:" and suffix = "keep", while
original_handle = "!e!".
Implementations§
Source§impl Tag
impl Tag
Sourcepub fn new(handle: impl Into<String>, suffix: impl Into<String>) -> Self
pub fn new(handle: impl Into<String>, suffix: impl Into<String>) -> Self
Create a tag from resolved parts.
This is mainly useful for tests and consumers constructing parser-compatible tags by hand.
When the original source handle matters, use Self::with_original_handle.
Sourcepub fn with_original_handle(
handle: impl Into<String>,
suffix: impl Into<String>,
original_handle: impl Into<String>,
) -> Self
pub fn with_original_handle( handle: impl Into<String>, suffix: impl Into<String>, original_handle: impl Into<String>, ) -> Self
Create a tag from resolved parts and the handle as written in the source.
Sourcepub fn core_suffix(&self) -> Option<&str>
pub fn core_suffix(&self) -> Option<&str>
Return the resolved YAML core-schema suffix for this tag, if it is a known core tag.
The tag is matched by its resolved URI, not by the source handle spelling. For example,
!!int, !<tag:yaml.org,2002:int>, and a %TAG split such as
%TAG !m! tag:yaml.org,2002:i followed by !m!nt all return Some("int").
Authored tag parts are left unchanged; use Self::parts, Self::original_parts, or
Self::original to inspect those spellings.
Sourcepub fn suffix_in_namespace(&self, prefix: &str) -> Option<Cow<'_, str>>
pub fn suffix_in_namespace(&self, prefix: &str) -> Option<Cow<'_, str>>
Return the type name this tag resolves to within prefix, or None outside it.
Like Self::core_suffix, the tag is matched by its resolved handle ++ suffix URI,
not the source spelling, so !!omap, !<tag:yaml.org,2002:omap>, and a %TAG split
such as %TAG !o! tag:yaml.org,2002:o then !o!map all resolve to Some("omap") for
the tag:yaml.org,2002: prefix — but the name is not limited to the seven core types.
Borrows from self; allocates only when the handle extends past prefix.
Sourcepub fn is_yaml_core_schema(&self) -> bool
pub fn is_yaml_core_schema(&self) -> bool
Returns whether the tag is a YAML tag from the core schema (!!str, !!int, …).
The YAML specification specifies a list of tags for the Core Schema. This function uses the resolved tag URI, so it is independent of how the tag was split between handle and suffix.
§Return
Returns true if the resolved tag is a known YAML 1.2.2 Core Schema tag.
Sourcepub fn is_yaml_core_schema_tag(&self, suffix: &str) -> bool
pub fn is_yaml_core_schema_tag(&self, suffix: &str) -> bool
Return true for a YAML core-schema tag with the given suffix.
For example, this matches core-schema tags such as !!str, !!int, !!float, !!bool,
!!null, !!map, or !!seq after tag resolution.
Sourcepub fn is_custom(&self) -> bool
pub fn is_custom(&self) -> bool
Return true for a tag outside the YAML 1.2.2 Core Schema tag set.
This checks the resolved tag URI, not just the tag handle spelling. For example,
tag:yaml.org,2002:timestamp is in the YAML tag namespace, but it is not a YAML 1.2.2
Core Schema tag.
Sourcepub fn original_parts(&self) -> (&str, &str)
pub fn original_parts(&self) -> (&str, &str)
Return the tag as (original_handle, suffix) using the handle from the source token.
This is useful when a consumer needs author spelling such as !e!keep instead of the
resolved URI tag tag:example.com,2000:keep.
Sourcepub fn original(&self) -> String
pub fn original(&self) -> String
Return the tag spelling reconstructed from the source handle and suffix.
For ordinary shorthand tags this returns the author-facing spelling, such as !e!keep or
!!str. For verbatim tags this returns a normalized verbatim spelling such as
!<tag:example.com,2000:thing>, not necessarily the byte-exact source token.