logo
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

Creates a new Document.

Gets the first child node with a matching name.

Gets a reference to the first child node with a matching name.

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()));

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()]);

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.

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()]);

Returns a reference to this document’s child nodes.

Returns a mutable reference to this document’s child nodes.

Gets leading text (whitespace, comments) for this KdlDocument.

Sets leading text (whitespace, comments) for this KdlDocument.

Gets trailing text (whitespace, comments) for this KdlDocument.

Sets trailing text (whitespace, comments) for this KdlDocument.

Length of this document when rendered as a string.

Returns true if this document is completely empty (including whitespace)

Clears leading and trailing text (whitespace, comments). KdlNodes in this document will be unaffected.

Auto-formats this Document, making everything nice while preserving comments.

Formats the document and removes all comments from the document.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.