pub struct KdlNode { /* private fields */ }
Expand description
Represents an individual KDL
Node
inside a
KDL Document.
Implementations
sourceimpl KdlNode
impl KdlNode
sourcepub fn new(name: impl Into<KdlIdentifier>) -> Self
pub fn new(name: impl Into<KdlIdentifier>) -> Self
Creates a new KdlNode with a given name.
sourcepub fn name(&self) -> &KdlIdentifier
pub fn name(&self) -> &KdlIdentifier
Gets this node’s name.
sourcepub fn name_mut(&mut self) -> &mut KdlIdentifier
pub fn name_mut(&mut self) -> &mut KdlIdentifier
Gets a mutable reference to this node’s name.
sourcepub fn set_name(&mut self, name: impl Into<KdlIdentifier>)
pub fn set_name(&mut self, name: impl Into<KdlIdentifier>)
Sets this node’s name.
sourcepub fn span(&self) -> &SourceSpan
pub fn span(&self) -> &SourceSpan
Gets this node’s span.
This value will be properly initialized when created via [KdlDocument::parse
]
but may become invalidated if the document is mutated. We do not currently
guarantee this to yield any particularly consistent results at that point.
sourcepub fn span_mut(&mut self) -> &mut SourceSpan
pub fn span_mut(&mut self) -> &mut SourceSpan
Gets a mutable reference to this node’s span.
sourcepub fn set_span(&mut self, span: impl Into<SourceSpan>)
pub fn set_span(&mut self, span: impl Into<SourceSpan>)
Sets this node’s span.
sourcepub fn ty(&self) -> Option<&KdlIdentifier>
pub fn ty(&self) -> Option<&KdlIdentifier>
Gets the node’s type identifier, if any.
sourcepub fn ty_mut(&mut self) -> &mut Option<KdlIdentifier>
pub fn ty_mut(&mut self) -> &mut Option<KdlIdentifier>
Gets a mutable reference to the node’s type identifier.
sourcepub fn set_ty(&mut self, ty: impl Into<KdlIdentifier>)
pub fn set_ty(&mut self, ty: impl Into<KdlIdentifier>)
Sets the node’s type identifier.
sourcepub fn entries(&self) -> &[KdlEntry]
pub fn entries(&self) -> &[KdlEntry]
Returns a reference to this node’s entries (arguments and properties).
sourcepub fn entries_mut(&mut self) -> &mut Vec<KdlEntry>
pub fn entries_mut(&mut self) -> &mut Vec<KdlEntry>
Returns a mutable reference to this node’s entries (arguments and properties).
sourcepub fn set_leading(&mut self, leading: impl Into<String>)
pub fn set_leading(&mut self, leading: impl Into<String>)
Sets leading text (whitespace, comments) for this node.
sourcepub fn before_children(&self) -> Option<&str>
pub fn before_children(&self) -> Option<&str>
Gets text (whitespace, comments) right before the children block’s starting {
.
sourcepub fn set_before_children(&mut self, before: impl Into<String>)
pub fn set_before_children(&mut self, before: impl Into<String>)
Gets text (whitespace, comments) right before the children block’s starting {
.
sourcepub fn trailing(&self) -> Option<&str>
pub fn trailing(&self) -> Option<&str>
Gets trailing text (whitespace, comments) for this node.
sourcepub fn set_trailing(&mut self, trailing: impl Into<String>)
pub fn set_trailing(&mut self, trailing: impl Into<String>)
Sets trailing text (whitespace, comments) for this node.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this node is completely empty (including whitespace).
sourcepub fn clear_fmt(&mut self)
pub fn clear_fmt(&mut self)
Clears leading and trailing text (whitespace, comments), as well as the space before the children block, if any. Individual entries and their formatting will be preserved.
If you want to clear formatting on all children and entries as well,
use Self::clear_fmt_recursive
.
sourcepub fn clear_fmt_recursive(&mut self)
pub fn clear_fmt_recursive(&mut self)
Clears leading and trailing text (whitespace, comments), as well as the space before the children block, if any. Individual entries and children formatting will also be cleared.
sourcepub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlEntry>
pub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlEntry>
Fetches an entry by key. Number keys will look up arguments, strings will look up properties.
sourcepub fn get_mut(&mut self, key: impl Into<NodeKey>) -> Option<&mut KdlEntry>
pub fn get_mut(&mut self, key: impl Into<NodeKey>) -> Option<&mut KdlEntry>
Fetches a mutable referene to an entry by key. Number keys will look up arguments, strings will look up properties.
sourcepub fn insert(
&mut self,
key: impl Into<NodeKey>,
entry: impl Into<KdlEntry>
) -> Option<KdlEntry>
pub fn insert(
&mut self,
key: impl Into<NodeKey>,
entry: impl Into<KdlEntry>
) -> Option<KdlEntry>
Inserts an entry into this node. If an entry already exists with the same key, it will be replaced and the previous entry will be returned.
Numerical keys will insert arguments, string keys will insert properties.
sourcepub fn remove(&mut self, key: impl Into<NodeKey>) -> Option<KdlEntry>
pub fn remove(&mut self, key: impl Into<NodeKey>) -> Option<KdlEntry>
Removes an entry from this node. If an entry already exists with the same key, it will be returned.
Numerical keys will remove arguments, string keys will remove properties.
sourcepub fn push(&mut self, entry: impl Into<KdlEntry>)
pub fn push(&mut self, entry: impl Into<KdlEntry>)
Shorthand for self.entries_mut().push(entry)
.
sourcepub fn clear_entries(&mut self)
pub fn clear_entries(&mut self)
Shorthand for self.entries_mut().clear()
sourcepub fn children(&self) -> Option<&KdlDocument>
pub fn children(&self) -> Option<&KdlDocument>
Returns a reference to this node’s children, if any.
sourcepub fn children_mut(&mut self) -> &mut Option<KdlDocument>
pub fn children_mut(&mut self) -> &mut Option<KdlDocument>
Returns a mutable reference to this node’s children, if any.
sourcepub fn set_children(&mut self, children: KdlDocument)
pub fn set_children(&mut self, children: KdlDocument)
Sets the KdlDocument representing this node’s children.
sourcepub fn clear_children(&mut self)
pub fn clear_children(&mut self)
Removes this node’s children completely.
sourcepub fn ensure_children(&mut self) -> &mut KdlDocument
pub fn ensure_children(&mut self) -> &mut KdlDocument
Returns a mutable reference to this node’s children KdlDocument
,
creating one first if one does not already exist.
sourcepub fn fmt_no_comments(&mut self)
pub fn fmt_no_comments(&mut self)
Auto-formats this node and its contents, stripping comments.