pub struct KdlNode { /* private fields */ }
Expand description
Represents an individual KDL
Node
inside a
KDL Document.
Implementations§
Source§impl 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 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 clear_format(&mut self)
pub fn clear_format(&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_format_recursive
.
Sourcepub fn clear_format_recursive(&mut self)
pub fn clear_format_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 entry(&self, key: impl Into<NodeKey>) -> Option<&KdlEntry>
pub fn entry(&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 entry_mut(&mut self, key: impl Into<NodeKey>) -> Option<&mut KdlEntry>
pub fn entry_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 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 format(&self) -> Option<&KdlNodeFormat>
pub fn format(&self) -> Option<&KdlNodeFormat>
Gets the formatting details (including whitespace and comments) for this node.
Sourcepub fn format_mut(&mut self) -> Option<&mut KdlNodeFormat>
pub fn format_mut(&mut self) -> Option<&mut KdlNodeFormat>
Gets a mutable reference to this node’s formatting details.
Sourcepub fn set_format(&mut self, format: KdlNodeFormat)
pub fn set_format(&mut self, format: KdlNodeFormat)
Sets the formatting details for this node.
Sourcepub fn autoformat(&mut self)
pub fn autoformat(&mut self)
Auto-formats this node and its contents.
Sourcepub fn autoformat_no_comments(&mut self)
pub fn autoformat_no_comments(&mut self)
Auto-formats this node and its contents, stripping comments.
Sourcepub fn autoformat_config(&mut self, config: &FormatConfig<'_>)
pub fn autoformat_config(&mut self, config: &FormatConfig<'_>)
Auto-formats this node and its contents according to config
.
Sourcepub fn parse(s: &str) -> Result<Self, KdlError>
pub fn parse(s: &str) -> Result<Self, KdlError>
Parses a string into a node.
If the v1-fallback
feature is enabled, this method will first try to
parse the string as a KDL v2 node, and, if that fails, it will try
to parse again as a KDL v1 node. If both fail, only the v2 parse
errors will be returned.
Source§impl KdlNode
impl KdlNode
Sourcepub fn iter(&self) -> EntryIter<'_> ⓘ
pub fn iter(&self) -> EntryIter<'_> ⓘ
Returns an iterator over the node’s entries, including properties.
Sourcepub fn iter_mut(&mut self) -> EntryIterMut<'_> ⓘ
pub fn iter_mut(&mut self) -> EntryIterMut<'_> ⓘ
Returns a mutable iterator over the node’s entries, including properties.
Sourcepub fn iter_children(&self) -> ChildrenIter<'_> ⓘ
pub fn iter_children(&self) -> ChildrenIter<'_> ⓘ
Returns an iterator over the node’s children, if any. Nodes without children will return an empty iterator.
Sourcepub fn iter_children_mut(&mut self) -> ChildrenIterMut<'_> ⓘ
pub fn iter_children_mut(&mut self) -> ChildrenIterMut<'_> ⓘ
Returns a mutable iterator over the node’s children, if any. Nodes without children will return an empty iterator.
Sourcepub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlValue>
pub fn get(&self, key: impl Into<NodeKey>) -> Option<&KdlValue>
Gets a value 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 KdlValue>
pub fn get_mut(&mut self, key: impl Into<NodeKey>) -> Option<&mut KdlValue>
Fetches a mutable referene to an value by key. Number keys will look up arguments, strings will look up properties.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this node is completely empty (including whitespace).
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 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 string 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 sort_by<F>(&mut self, compare: F)
pub fn sort_by<F>(&mut self, compare: F)
Sorts the slice with a comparison function, preserving initial order of equal elements.
Sourcepub fn sort_by_key<K, F>(&mut self, f: F)
pub fn sort_by_key<K, F>(&mut self, f: F)
Sorts the slice with a key extraction function, preserving initial order of equal elements.
Trait Implementations§
impl Eq for KdlNode
Auto Trait Implementations§
impl Freeze for KdlNode
impl RefUnwindSafe for KdlNode
impl Send for KdlNode
impl Sync for KdlNode
impl Unpin for KdlNode
impl UnwindSafe for KdlNode
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§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more