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
impl MarkedMappingNode
source§impl MarkedMappingNode
impl MarkedMappingNode
sourcepub fn new_empty(span: Span) -> Self
pub fn new_empty(span: Span) -> Self
Create a new empty mapping node
let node = MarkedMappingNode::new_empty(Span::new_blank());
sourcepub fn new(span: Span, value: LinkedHashMap<MarkedScalarNode, Node>) -> Self
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());
sourcepub fn get_node(&self, index: &str) -> Option<&Node>
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");
sourcepub fn get_scalar(&self, index: &str) -> Option<&MarkedScalarNode>
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");
sourcepub fn get_sequence(&self, index: &str) -> Option<&MarkedSequenceNode>
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");
sourcepub fn get_mapping(&self, index: &str) -> Option<&MarkedMappingNode>
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>>§
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn clear(&mut self)
pub fn iter(&self) -> Iter<'_, K, V> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, K, V>
pub fn drain(&mut self) -> Drain<'_, K, V>
pub fn keys(&self) -> Keys<'_, K, V>
pub fn values(&self) -> Values<'_, K, V>
pub fn values_mut(&mut self) -> ValuesMut<'_, K, V>
pub fn front(&self) -> Option<(&K, &V)>
pub fn back(&self) -> Option<(&K, &V)>
pub fn retain<F>(&mut self, f: F)
pub fn hasher(&self) -> &S
pub fn capacity(&self) -> usize
pub fn entry(&mut self, key: K) -> Entry<'_, K, V, S>
pub fn get<Q>(&self, k: &Q) -> Option<&V>
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)>
pub fn contains_key<Q>(&self, k: &Q) -> bool
pub fn get_mut<Q>(&mut self, k: &Q) -> Option<&mut V>
sourcepub fn insert(&mut self, k: K, v: V) -> Option<V>
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.
sourcepub fn replace(&mut self, k: K, v: V) -> Option<V>
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.
pub fn remove<Q>(&mut self, k: &Q) -> Option<V>
pub fn remove_entry<Q>(&mut self, k: &Q) -> Option<(K, V)>
pub fn pop_front(&mut self) -> Option<(K, V)>
pub fn pop_back(&mut self) -> Option<(K, V)>
sourcepub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn to_front<Q>(&mut self, k: &Q) -> Option<&mut V>
If an entry with this key exists, move it to the front of the list and return a reference to the value.
sourcepub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
pub fn to_back<Q>(&mut self, k: &Q) -> Option<&mut V>
If an entry with this key exists, move it to the back of the list and return a reference to the value.
pub fn reserve(&mut self, additional: usize)
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
pub fn shrink_to_fit(&mut self)
pub fn retain_with_order<F>(&mut self, f: F)
sourcepub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, V, S>
pub fn cursor_front_mut(&mut self) -> CursorMut<'_, K, V, S>
Returns the CursorMut
over the front node.
Note: The CursorMut
is pointing to the guard node in an empty LinkedHashMap
and
will always return None
as its current element, regardless of any move in any
direction.
sourcepub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, V, S>
pub fn cursor_back_mut(&mut self) -> CursorMut<'_, K, V, S>
Returns the CursorMut
over the back node.
Note: The CursorMut
is pointing to the guard node in an empty LinkedHashMap
and
will always return None
as its current element, regardless of any move in any
direction.
pub fn raw_entry(&self) -> RawEntryBuilder<'_, K, V, S>
pub fn raw_entry_mut(&mut self) -> RawEntryBuilderMut<'_, K, V, S>
Trait Implementations§
source§impl Clone for MarkedMappingNode
impl Clone for MarkedMappingNode
source§fn clone(&self) -> MarkedMappingNode
fn clone(&self) -> MarkedMappingNode
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for MarkedMappingNode
impl Debug for MarkedMappingNode
source§impl Deref for MarkedMappingNode
impl Deref for MarkedMappingNode
§type Target = LinkedHashMap<MarkedScalarNode, Node>
type Target = LinkedHashMap<MarkedScalarNode, Node>
source§impl DerefMut for MarkedMappingNode
impl DerefMut for MarkedMappingNode
source§impl From<LinkedHashMap<MarkedScalarNode, Node>> for MarkedMappingNode
impl From<LinkedHashMap<MarkedScalarNode, Node>> for MarkedMappingNode
source§fn from(value: LinkedHashMap<MarkedScalarNode, Node>) -> Self
fn from(value: LinkedHashMap<MarkedScalarNode, Node>) -> Self
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<MarkedMappingNode> for Yaml
impl From<MarkedMappingNode> for Yaml
source§fn from(value: MarkedMappingNode) -> Self
fn from(value: MarkedMappingNode) -> Self
source§impl<T, U> FromIterator<(T, U)> for MarkedMappingNode
impl<T, U> FromIterator<(T, U)> for MarkedMappingNode
source§fn from_iter<I: IntoIterator<Item = (T, U)>>(iter: I) -> Self
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
impl Hash for MarkedMappingNode
source§impl<'de> IntoDeserializer<'de, Error> for &'de MarkedMappingNode
impl<'de> IntoDeserializer<'de, Error> for &'de MarkedMappingNode
§type Deserializer = MarkedMappingNodeDeserializer<'de>
type Deserializer = MarkedMappingNodeDeserializer<'de>
source§fn into_deserializer(self) -> Self::Deserializer
fn into_deserializer(self) -> Self::Deserializer
source§impl PartialEq for MarkedMappingNode
impl PartialEq for MarkedMappingNode
impl Eq for MarkedMappingNode
Auto Trait Implementations§
impl Freeze for MarkedMappingNode
impl RefUnwindSafe for MarkedMappingNode
impl Send for MarkedMappingNode
impl Sync for MarkedMappingNode
impl Unpin for MarkedMappingNode
impl UnwindSafe for MarkedMappingNode
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
)