Enum marked_yaml::types::Node
source · pub enum Node {
Scalar(MarkedScalarNode),
Mapping(MarkedMappingNode),
Sequence(MarkedSequenceNode),
}
Expand description
A marked YAML node
NOTE: Nodes are considered equal even if they don’t come from the same place. i.e. their spans are ignored for equality and hashing
use marked_yaml::parse_yaml;
let node = parse_yaml(100, "{foo: bar}").unwrap();
assert!(node.as_mapping().is_some());
Variants§
Scalar(MarkedScalarNode)
A YAML scalar
You can test if a node is a scalar, and retrieve it as one if you so wish.
Mapping(MarkedMappingNode)
A YAML mapping
You can test if a node is a mapping, and retrieve it as one if you so wish.
Sequence(MarkedSequenceNode)
A YAML sequence
You can test if a node is a sequence, and retrieve it as one if you so wish.
Implementations§
source§impl Node
impl Node
sourcepub fn span(&self) -> &Span
pub fn span(&self) -> &Span
Retrieve the Span from the contained Node
let node: Node = "foobar".into();
let span = node.span();
assert_eq!(span.start(), None);
sourcepub fn span_mut(&mut self) -> &mut Span
pub fn span_mut(&mut self) -> &mut Span
Retrieve the Span from the contained Node, mutably
let mut node: Node = "foobar".into();
let mut span = node.span_mut();
assert_eq!(span.start(), None);
span.set_start(Some(Marker::new(0, 1, 0)));
assert_eq!(span.start(), Some(&Marker::new(0, 1, 0)));
sourcepub fn as_scalar(&self) -> Option<&MarkedScalarNode>
pub fn as_scalar(&self) -> Option<&MarkedScalarNode>
Retrieve the scalar from this node if there is one
let node: Node = "foobar".into();
let scalar = node.as_scalar();
assert!(scalar.is_some());
sourcepub fn as_sequence(&self) -> Option<&MarkedSequenceNode>
pub fn as_sequence(&self) -> Option<&MarkedSequenceNode>
Retrieve the sequence from this node if there is one
let node: Node = vec!["foobar"].into();
let sequence = node.as_sequence();
assert!(sequence.is_some());
sourcepub fn as_mapping(&self) -> Option<&MarkedMappingNode>
pub fn as_mapping(&self) -> Option<&MarkedMappingNode>
Retrieve the mapping from this node if there is one
let node: Node = parse_yaml(0, "{foobar: baz}").unwrap();
let mapping = node.as_mapping();
assert!(mapping.is_some());
sourcepub fn as_scalar_mut(&mut self) -> Option<&mut MarkedScalarNode>
pub fn as_scalar_mut(&mut self) -> Option<&mut MarkedScalarNode>
Retrieve the scalar from this node if there is one, mutably
let mut node: Node = "foobar".into();
let mut scalar = node.as_scalar_mut();
assert!(scalar.is_some());
sourcepub fn as_sequence_mut(&mut self) -> Option<&mut MarkedSequenceNode>
pub fn as_sequence_mut(&mut self) -> Option<&mut MarkedSequenceNode>
Retrieve the sequence from this node if there is one, mutably
let mut node: Node = vec!["foobar"].into();
let mut sequence = node.as_sequence_mut();
assert!(sequence.is_some());
sourcepub fn as_mapping_mut(&mut self) -> Option<&mut MarkedMappingNode>
pub fn as_mapping_mut(&mut self) -> Option<&mut MarkedMappingNode>
Retrieve the mapping from this node if there is one, mutably
let mut node: Node = parse_yaml(0, "{foobar: baz}").unwrap();
let mut mapping = node.as_mapping_mut();
assert!(mapping.is_some());
Trait Implementations§
source§impl From<LinkedHashMap<MarkedScalarNode, Node>> for Node
impl From<LinkedHashMap<MarkedScalarNode, Node>> for Node
source§fn from(value: LinkedHashMap<MarkedScalarNode, Node>) -> Node
fn from(value: LinkedHashMap<MarkedScalarNode, Node>) -> Node
source§impl From<MarkedMappingNode> for Node
impl From<MarkedMappingNode> for Node
source§fn from(value: MarkedMappingNode) -> Node
fn from(value: MarkedMappingNode) -> Node
source§impl From<MarkedSequenceNode> for Node
impl From<MarkedSequenceNode> for Node
source§fn from(value: MarkedSequenceNode) -> Node
fn from(value: MarkedSequenceNode) -> Node
source§impl<'de> IntoDeserializer<'de, Error> for &'de Node
impl<'de> IntoDeserializer<'de, Error> for &'de Node
§type Deserializer = NodeDeserializer<'de>
type Deserializer = NodeDeserializer<'de>
source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
source§impl PartialEq for Node
impl PartialEq for Node
source§impl TryFrom<Yaml> for Node
impl TryFrom<Yaml> for Node
source§fn try_from(value: YamlNode) -> Result<Self, Self::Error>
fn try_from(value: YamlNode) -> Result<Self, Self::Error>
Convert from any yaml_rust::Yaml
to a Node
let docs = YamlLoader::load_from_str("[1, 2]").unwrap();
let yaml = docs.into_iter().next().unwrap();
let node = Node::try_from(yaml).unwrap();
§type Error = YamlConversionError
type Error = YamlConversionError
impl Eq for Node
impl StructuralPartialEq for Node
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnwindSafe for Node
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)