Struct kdl::KdlDocument
source · [−]pub struct KdlDocument { /* private fields */ }
Expand description
Represents a KDL
Document
.
This type is also used to manage a KdlNode
’s Children Block
,
when present.
Examples
The easiest way to create a KdlDocument
is to parse it:
let kdl: KdlDocument = "foo 1 2 3\nbar 4 5 6".parse().expect("parse failed");
Implementations
sourceimpl KdlDocument
impl KdlDocument
sourcepub fn get(&self, name: &str) -> Option<&KdlNode>
pub fn get(&self, name: &str) -> Option<&KdlNode>
Gets the first child node with a matching name.
sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut KdlNode>
pub fn get_mut(&mut self, name: &str) -> Option<&mut KdlNode>
Gets a reference to the first child node with a matching name.
sourcepub fn get_arg(&self, name: &str) -> Option<&KdlValue>
pub fn get_arg(&self, name: &str) -> Option<&KdlValue>
Gets the first argument (value) of the first child node with a matching name. This is a shorthand utility for cases where a document is being used as a key/value store.
Examples
Given a document like this:
foo 1
bar false
You can fetch the value of foo
in a single call like this:
assert_eq!(doc.get_arg("foo"), Some(&1.into()));
sourcepub fn get_args(&self, name: &str) -> Vec<&KdlValue>
pub fn get_args(&self, name: &str) -> Vec<&KdlValue>
Gets the all node arguments (value) of the first child node with a matching name. This is a shorthand utility for cases where a document is being used as a key/value store and the value is expected to be array-ish.
If a node has no arguments, this will return an empty array.
Examples
Given a document like this:
foo 1 2 3
bar false
You can fetch the arguments for foo
in a single call like this:
assert_eq!(doc.get_args("foo"), vec![&1.into(), &2.into(), &3.into()]);
sourcepub fn get_arg_mut(&mut self, name: &str) -> Option<&mut KdlValue>
pub fn get_arg_mut(&mut self, name: &str) -> Option<&mut KdlValue>
Gets a mutable reference to the first argument (value) of the first child node with a matching name. This is a shorthand utility for cases where a document is being used as a key/value store.
sourcepub fn get_dash_vals(&self, name: &str) -> Vec<&KdlValue>
pub fn get_dash_vals(&self, name: &str) -> Vec<&KdlValue>
This utility makes it easy to interact with a KDL convention where
child nodes named -
are treated as array-ish values.
Examples
Given a document like this:
foo {
- 1
- 2
- false
}
You can fetch the dashed child values of foo
in a single call like this:
assert_eq!(doc.get_dash_vals("foo"), vec![&1.into(), &2.into(), &false.into()]);
sourcepub fn nodes_mut(&mut self) -> &mut Vec<KdlNode>
pub fn nodes_mut(&mut self) -> &mut Vec<KdlNode>
Returns a mutable reference to this document’s child nodes.
sourcepub fn leading(&self) -> Option<&str>
pub fn leading(&self) -> Option<&str>
Gets leading text (whitespace, comments) for this KdlDocument.
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 KdlDocument.
sourcepub fn trailing(&self) -> Option<&str>
pub fn trailing(&self) -> Option<&str>
Gets trailing text (whitespace, comments) for this KdlDocument.
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 KdlDocument.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if this document is completely empty (including whitespace)
sourcepub fn clear_fmt(&mut self)
pub fn clear_fmt(&mut self)
Clears leading and trailing text (whitespace, comments). KdlNode
s in
this document will be unaffected.
sourcepub fn fmt(&mut self)
pub fn fmt(&mut self)
Auto-formats this Document, making everything nice while preserving comments.
sourcepub fn fmt_no_comments(&mut self)
pub fn fmt_no_comments(&mut self)
Formats the document and removes all comments from the document.
Trait Implementations
sourceimpl Clone for KdlDocument
impl Clone for KdlDocument
sourcefn clone(&self) -> KdlDocument
fn clone(&self) -> KdlDocument
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for KdlDocument
impl Debug for KdlDocument
sourceimpl Default for KdlDocument
impl Default for KdlDocument
sourcefn default() -> KdlDocument
fn default() -> KdlDocument
Returns the “default value” for a type. Read more
sourceimpl Display for KdlDocument
impl Display for KdlDocument
sourceimpl FromStr for KdlDocument
impl FromStr for KdlDocument
sourceimpl IntoIterator for KdlDocument
impl IntoIterator for KdlDocument
sourceimpl PartialEq<KdlDocument> for KdlDocument
impl PartialEq<KdlDocument> for KdlDocument
sourcefn eq(&self, other: &KdlDocument) -> bool
fn eq(&self, other: &KdlDocument) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &KdlDocument) -> bool
fn ne(&self, other: &KdlDocument) -> bool
This method tests for !=
.
impl StructuralPartialEq for KdlDocument
Auto Trait Implementations
impl RefUnwindSafe for KdlDocument
impl Send for KdlDocument
impl Sync for KdlDocument
impl Unpin for KdlDocument
impl UnwindSafe for KdlDocument
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more