[][src]Enum marked_yaml::types::Node

pub enum Node {
    Scalar(MarkedScalarNode),
    Mapping(MarkedMappingNode),
    Sequence(MarkedSequenceNode),
}

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

A YAML scalar

You can test if a node is a scalar, and retrieve it as one if you so wish.

A YAML mapping

You can test if a node is a mapping, and retrieve it as one if you so wish.

A YAML sequence

You can test if a node is a sequence, and retrieve it as one if you so wish.

Methods

impl Node[src]

pub fn span(&self) -> &Span[src]

Retrieve the Span from the contained Node

let node: Node = "foobar".into();
let span = node.span();
assert_eq!(span.start(), None);

pub fn span_mut(&mut self) -> &mut Span[src]

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)));

pub fn as_scalar(&self) -> Option<&MarkedScalarNode>[src]

Retrieve the scalar from this node if there is one

let node: Node = "foobar".into();
let scalar = node.as_scalar();
assert!(scalar.is_some());

pub fn as_sequence(&self) -> Option<&MarkedSequenceNode>[src]

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());

pub fn as_mapping(&self) -> Option<&MarkedMappingNode>[src]

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());

pub fn as_scalar_mut(&mut self) -> Option<&mut MarkedScalarNode>[src]

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());

pub fn as_sequence_mut(&mut self) -> Option<&mut MarkedSequenceNode>[src]

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());

pub fn as_mapping_mut(&mut self) -> Option<&mut MarkedMappingNode>[src]

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

impl Clone for Node[src]

impl Debug for Node[src]

impl Eq for Node[src]

impl From<LinkedHashMap<MarkedScalarNode, Node, RandomState>> for Node[src]

impl From<MarkedMappingNode> for Node[src]

impl From<MarkedSequenceNode> for Node[src]

impl From<Node> for YamlNode[src]

impl<T> From<T> for Node where
    T: Into<MarkedScalarNode>, 
[src]

impl<T> From<Vec<T>> for Node where
    T: Into<Node>, 
[src]

impl Hash for Node[src]

impl PartialEq<Node> for Node[src]

impl StructuralEq for Node[src]

impl StructuralPartialEq for Node[src]

impl TryFrom<Yaml> for Node[src]

type Error = YamlConversionError

The type returned in the event of a conversion error.

fn try_from(value: YamlNode) -> Result<Self, Self::Error>[src]

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();

Auto Trait Implementations

impl RefUnwindSafe for Node

impl Send for Node

impl Sync for Node

impl Unpin for Node

impl UnwindSafe for Node

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.