Skip to main content

KdlSource

Trait KdlSource 

Source
pub trait KdlSource {
    // Required methods
    fn parse(&self, source: &[u8]) -> Result<Document, ParseError>;
    fn format(&self, doc: &Document) -> Result<Vec<u8>, FormatError>;
}
Expand description

Contract for a type that can parse and format .zen source bytes.

Required Methods§

Source

fn parse(&self, source: &[u8]) -> Result<Document, ParseError>

Parse raw .zen bytes into a Document AST.

§Errors

Returns a ParseError if the bytes are not valid UTF-8, not valid KDL, or do not conform to the minimal Zenith schema.

Source

fn format(&self, doc: &Document) -> Result<Vec<u8>, FormatError>

Serialize a Document AST back to canonical .zen bytes.

The output is idempotent: format(format(doc)) == format(doc) for all valid documents. Returns Err only for genuinely un-serializable states (unreachable for valid v0 input).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§