pub struct MappingEntry(/* private fields */);Expand description
A key-value pair in a YAML mapping
Note: This type uses interior mutability through the rowan library.
Mutation methods work even when called through &self. See the crate-level
documentation for details on the mutability model.
Implementations§
Source§impl MappingEntry
impl MappingEntry
Sourcepub fn key_matches(&self, key: impl AsYaml) -> bool
pub fn key_matches(&self, key: impl AsYaml) -> bool
Return true if the key of this entry matches key.
Uses semantic YAML equality, so quoting style differences are ignored:
"foo", 'foo', and foo all match the scalar "foo". Returns
false if this entry has no key node.
Sourcepub fn key_node(&self) -> Option<YamlNode>
pub fn key_node(&self) -> Option<YamlNode>
Get the key of this entry as a YamlNode.
Returns None for malformed entries that have no key.
Sourcepub fn value_node(&self) -> Option<YamlNode>
pub fn value_node(&self) -> Option<YamlNode>
Get the value of this entry as a YamlNode.
Returns None for malformed entries that have no value.
Sourcepub fn new(
key: impl AsYaml,
value: impl AsYaml,
flow_context: bool,
use_explicit_key: bool,
) -> Self
pub fn new( key: impl AsYaml, value: impl AsYaml, flow_context: bool, use_explicit_key: bool, ) -> Self
Create a new mapping entry (key-value pair) not yet attached to any mapping.
The entry is built as a standalone CST node; attach it to a mapping with
one of the insert_* methods. Block-style values (mappings, sequences)
are indented with 2 spaces relative to the key.
Sourcepub fn set_value(&self, new_value: impl AsYaml, flow_context: bool)
pub fn set_value(&self, new_value: impl AsYaml, flow_context: bool)
Replace the value of this entry in place, preserving the key and surrounding whitespace.
Sourcepub fn discard(self)
pub fn discard(self)
Detach this entry from its parent mapping, effectively removing it.
The entry node is detached from the tree; the MappingEntry value is
consumed. To retrieve the removed entry from a mapping (and get back a
MappingEntry you can inspect), use Mapping::remove instead.
Sourcepub fn remove(self)
pub fn remove(self)
Remove this entry from its parent mapping.
This is a convenience method that calls discard
internally. It’s useful when you have a MappingEntry (e.g., from
find_all_entries_by_key) and want
to remove it without retrieving it from the mapping again.
Consumes self and detaches the entry from the parent mapping.
Trait Implementations§
Source§impl AstNode for MappingEntry
impl AstNode for MappingEntry
Source§impl Clone for MappingEntry
impl Clone for MappingEntry
Source§fn clone(&self) -> MappingEntry
fn clone(&self) -> MappingEntry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more