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 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 checks whether the handle (but not the suffix) is the handle for the YAML Core Schema.
§Return
Returns true if the handle is tag:yaml.org,2002:, false otherwise.
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 core-schema namespace.
This checks only the tag handle. It returns false for any tag whose handle is
tag:yaml.org,2002:, regardless of suffix.
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.