Struct marked_yaml::types::MarkedMappingNode

source ·
pub struct MarkedMappingNode { /* private fields */ }
Expand description

A marked YAML mapping node

Mapping nodes in YAML are defined as a key/value mapping where the keys are unique and always scalars, whereas values may be YAML nodes of any kind.

Because some users of this crate may need to care about insertion order we use hashlink::LinkedHashMap for this.

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, Marker, Span};
let node = parse_yaml(100, "{foo: bar}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.span(), &Span::new_with_marks(Marker::new(100, 1, 1), Marker::new(100, 1, 10)));

Implementations§

source§

impl MarkedMappingNode

source

pub fn span(&self) -> &Span

Retrieve the Span from this node.

let node = MarkedMappingNode::new_empty(Span::new_blank());
assert_eq!(node.span(), &Span::new_blank());
source

pub fn span_mut(&mut self) -> &mut Span

Retrieve the Span from this node mutably.

let mut node = MarkedMappingNode::new_empty(Span::new_blank());
node.span_mut().set_start(Some(Marker::new(0, 1, 0)));
assert_eq!(node.span().start(), Some(&Marker::new(0, 1, 0)));
source§

impl MarkedMappingNode

source

pub fn new_empty(span: Span) -> Self

Create a new empty mapping node

let node = MarkedMappingNode::new_empty(Span::new_blank());
source

pub fn new(span: Span, value: LinkedHashMap<MarkedScalarNode, Node>) -> Self

Create a new mapping node from the given hash table

let node = MarkedMappingNode::new(Span::new_blank(), LinkedHashMap::new());
source

pub fn get_node(&self, index: &str) -> Option<&Node>

Get the node for the given string key

If the index is not found then None is returned.

let node = parse_yaml(0, "{key: value}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.get_node("key")
    .and_then(Node::as_scalar)
    .map(MarkedScalarNode::as_str)
    .unwrap(),
    "value");
source

pub fn get_scalar(&self, index: &str) -> Option<&MarkedScalarNode>

Get the scalar for the given string key

If the key is not found, or the node for that key is not a scalar node, then None will be returned.

let node = parse_yaml(0, "{key: value}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.get_scalar("key")
    .map(MarkedScalarNode::as_str)
    .unwrap(),
    "value");
source

pub fn get_sequence(&self, index: &str) -> Option<&MarkedSequenceNode>

Get the sequence at the given index

If the key is not found, or the node for that key is not a sequence node, then None will be returned.

let node = parse_yaml(0, "{key: [value]}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.get_sequence("key")
    .and_then(|s| s.get_scalar(0))
    .map(MarkedScalarNode::as_str)
    .unwrap(),
    "value");
source

pub fn get_mapping(&self, index: &str) -> Option<&MarkedMappingNode>

Get the mapping at the given index

If the key is not found, or the node for that key is not a mapping node, then None will be returned.

let node = parse_yaml(0, "{key: {inner: value}}").unwrap();
let map = node.as_mapping().unwrap();
assert_eq!(map.get_mapping("key")
    .and_then(|m| m.get_scalar("inner"))
    .map(MarkedScalarNode::as_str)
    .unwrap(),
    "value");

Methods from Deref<Target = LinkedHashMap<MarkedScalarNode, Node>>§

source

pub fn len(&self) -> usize

source

pub fn is_empty(&self) -> bool

source

pub fn clear(&mut self)

source

pub fn iter(&self) -> Iter<'_, K, V>

source

pub fn iter_mut(&mut self) -> IterMut<'_, K, V>

source

pub fn drain(&mut self) -> Drain<'_, K, V>

source

pub fn keys(&self) -> Keys<'_, K, V>

source

pub fn values(&self) -> Values<'_, K, V>

source

pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>

source

pub fn front(&self) -> Option<(&K, &V)>

source

pub fn back(&self) -> Option<(&K, &V)>

source

pub fn retain<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

source

pub fn hasher(&self) -> &S

source

pub fn capacity(&self) -> usize

source

pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>

source

pub fn get<Q>(&self, k: &Q) -> Option<&V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn contains_key<Q>(&self, k: &Q) -> bool
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn insert(&mut self, k: K, v: V) -> Option<V>

Inserts the given key / value pair at the back of the internal linked list.

Returns the previously set value, if one existed prior to this call. After this call, calling LinkedHashMap::back will return a reference to this key / value pair.

source

pub fn replace(&mut self, k: K, v: V) -> Option<V>

If the given key is not in this map, inserts the key / value pair at the back of the internal linked list and returns None, otherwise, replaces the existing value with the given value without moving the entry in the internal linked list and returns the previous value.

source

pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

source

pub fn pop_front(&mut self) -> Option<(K, V)>

source

pub fn pop_back(&mut self) -> Option<(K, V)>

source

pub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

If an entry with this key exists, move it to the front of the list and return a reference to the value.

source

pub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
where K: Borrow<Q>, Q: Hash + Eq + ?Sized,

If an entry with this key exists, move it to the back of the list and return a reference to the value.

source

pub fn reserve(&mut self, additional: usize)

source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

source

pub fn shrink_to_fit(&mut self)

source

pub fn retain_with_order<F>(&mut self, f: F)
where F: FnMut(&K, &mut V) -> bool,

source

pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>

source

pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>

Trait Implementations§

source§

impl Clone for MarkedMappingNode

source§

fn clone(&self) -> MarkedMappingNode

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 MarkedMappingNode

source§

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

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

impl Deref for MarkedMappingNode

§

type Target = LinkedHashMap<MarkedScalarNode, Node>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl DerefMut for MarkedMappingNode

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

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

source§

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

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<MarkedMappingNode> for Yaml

source§

fn from(value: MarkedMappingNode) -> Self

Converts to this type from the input type.
source§

impl<T, U> FromIterator<(T, U)> for MarkedMappingNode
where T: Into<MarkedScalarNode>, U: Into<Node>,

source§

fn from_iter<I: IntoIterator<Item = (T, U)>>(iter: I) -> Self

Allow collecting into a mapping node

hashmap.insert("hello", vec!["world".to_string()]);
hashmap.insert("key", vec!["value".to_string()]);
let node: MarkedMappingNode = hashmap.into_iter().collect();
source§

impl Hash for MarkedMappingNode

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 MarkedMappingNode

§

type Deserializer = MarkedMappingNodeDeserializer<'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 MarkedMappingNode

source§

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

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

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

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

impl Eq for MarkedMappingNode

Auto Trait Implementations§

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.