pub struct TaggedNode(/* private fields */);Expand description
A YAML tagged scalar (tag + value)
Note: This type uses interior mutability through the rowan library.
Mutation methods work even when called through &self. See the crate-level
documentation for details on the mutability model.
Implementations§
Source§impl TaggedNode
impl TaggedNode
Sourcepub fn tag(&self) -> Option<String>
pub fn tag(&self) -> Option<String>
Get the tag part of this tagged scalar (e.g., “!custom” from “!custom value”)
Sourcepub fn resolved_tag(&self) -> Option<String>
pub fn resolved_tag(&self) -> Option<String>
The tag as the %TAG directives of its document resolve it: in the
!! shorthand for a tag in the tag:yaml.org,2002: namespace however
it is written, verbatim (!<uri>) for another tag a declared handle
expands, and as written otherwise.
With %TAG !y! tag:yaml.org,2002: in effect, !y!int resolves to
!!int; tag still gives !y!int.
Sourcepub fn value(&self) -> Option<Scalar>
pub fn value(&self) -> Option<Scalar>
Get the value part of this tagged scalar (without the tag)
Sourcepub fn as_mapping(&self) -> Option<Mapping>
pub fn as_mapping(&self) -> Option<Mapping>
Get the collection this tag is attached to, if the tagged node wraps
a mapping (e.g. !custom on a block mapping).
Sourcepub fn as_sequence(&self) -> Option<Sequence>
pub fn as_sequence(&self) -> Option<Sequence>
Get the collection this tag is attached to, if the tagged node wraps
a sequence (e.g. !!seq on a flow sequence).
Sourcepub fn as_string(&self) -> Option<String>
pub fn as_string(&self) -> Option<String>
Get the string value of this tagged scalar (just the value part), with quotes stripped and escape sequences processed.
Returns None if the tag is on a collection or alias.
Sourcepub fn as_set(&self) -> Option<Set>
pub fn as_set(&self) -> Option<Set>
Extract a set from this tagged node if it has a !!set tag on a mapping.
Sourcepub fn as_ordered_mapping(&self) -> Option<Vec<MappingEntry>>
pub fn as_ordered_mapping(&self) -> Option<Vec<MappingEntry>>
Extract ordered mapping from this tagged node if it has a !!omap tag on a sequence.
Returns the entries of the inner sequence as MappingEntry values, each
holding a single key-value pair with full CST fidelity.
Sourcepub fn as_pairs(&self) -> Option<Vec<MappingEntry>>
pub fn as_pairs(&self) -> Option<Vec<MappingEntry>>
Extract pairs from this tagged node if it has a !!pairs tag on a sequence.
Returns the entries of the inner sequence as MappingEntry values.
Unlike !!omap, duplicate keys are allowed.
Trait Implementations§
Source§impl AsYaml for TaggedNode
impl AsYaml for TaggedNode
Source§fn build_content(
&self,
builder: &mut GreenNodeBuilder<'_>,
indent: usize,
flow_context: bool,
) -> bool
fn build_content( &self, builder: &mut GreenNodeBuilder<'_>, indent: usize, flow_context: bool, ) -> bool
Content on lines after the tag (a block collection, say) is shifted
to start at column indent, as for an untagged collection. Content
starting on the tag line (a flow collection) is shifted like an
untagged flow collection, keeping its continuation lines’ offset
from indent.