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

source

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

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

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

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

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

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

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

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 Clone for Node

source§

fn clone(&self) -> Node

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Node

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<LinkedHashMap<MarkedScalarNode, Node>> for Node

source§

fn from(value: LinkedHashMap<MarkedScalarNode, Node>) -> Node

Converts to this type from the input type.
source§

impl From<MarkedMappingNode> for Node

source§

fn from(value: MarkedMappingNode) -> Node

Converts to this type from the input type.
source§

impl From<MarkedSequenceNode> for Node

source§

fn from(value: MarkedSequenceNode) -> Node

Converts to this type from the input type.
source§

impl From<Node> for Yaml

source§

fn from(value: Node) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for Node

source§

fn from(value: T) -> Node

Converts to this type from the input type.
source§

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

source§

fn from(value: Vec<T>) -> Node

Converts to this type from the input type.
source§

impl Hash for Node

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<'de> IntoDeserializer<'de, Error> for &'de Node

§

type Deserializer = NodeDeserializer<'de>

The type of the deserializer being converted into.
source§

fn into_deserializer(self) -> Self::Deserializer

Convert this value into a deserializer.
source§

impl PartialEq for Node

source§

fn eq(&self, other: &Node) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl TryFrom<Yaml> for Node

source§

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

The type returned in the event of a conversion error.
source§

impl Eq for Node

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.