Expand description
KDL serialization and deserialization using facet-format.
This crate provides KDL (KDL Document Language) support using the
FormatParser and FormatSerializer traits from facet-format.
§KDL Format
KDL is a document language focused on human readability. Each document consists of nodes, where each node has:
- A name (identifier)
- Arguments (positional values after the name)
- Properties (key=value pairs)
- Children (nested nodes inside braces)
§Mapping to Rust Types
KDL nodes map to Rust structs using the kdl::* attributes:
#[facet(kdl::argument)]- Field receives a single positional argument#[facet(kdl::arguments)]- Field receives all positional arguments as Vec#[facet(kdl::property)]- Field receives a property value#[facet(kdl::child)]- Field receives a single child node#[facet(kdl::children)]- Field receives multiple child nodes as Vec
§Example
ⓘ
use facet::Facet;
use facet_kdl::from_str;
#[derive(Facet, Debug)]
struct Server {
#[facet(kdl::argument)]
host: String,
#[facet(kdl::property)]
port: u16,
}
let kdl = r#"server "localhost" port=8080"#;
let server: Server = from_str(kdl).unwrap();Structs§
- KdlDeserialize
Error - A KDL deserialization error with source code context for rich diagnostics.
- KdlParser
- KDL parser that converts KDL documents to FormatParser events.
- KdlProbe
- Probe stream for KDL parser.
- KdlSerialize
Error - Error type for KDL serialization.
- KdlSerializer
- KDL serializer implementing FormatSerializer.
Enums§
- Attr
- KDL attribute types for field and container configuration.
- Deserialize
Error - Error produced by
FormatDeserializer. - KdlError
- Error type for KDL parsing.
Functions§
- from_
slice - Deserialize a value from KDL bytes into an owned type.
- from_
slice_ borrowed - Deserialize a value from KDL bytes, allowing zero-copy borrowing.
- from_
str - Deserialize a value from a KDL string into an owned type.
- from_
str_ borrowed - Deserialize a value from a KDL string, allowing zero-copy borrowing.
- to_
string - Serialize a value to a KDL string.
- to_vec
- Serialize a value to KDL bytes.