Skip to main content

Backend

Trait Backend 

Source
pub(crate) trait Backend {
    type Document: Display + Editable;

    // Required methods
    fn build(
        &self,
        desired: &Annotated,
    ) -> Result<Self::Document, DocumentError>;
    fn finish(
        &self,
        current: &mut Self::Document,
        desired: &Self::Document,
        existing: Existing,
    );
    fn format(&self) -> Format;
    fn parse(&self, source: &str) -> Result<Self::Document, DocumentError>;
    fn string_leaf(
        &self,
        node: &<<Self as Backend>::Document as Editable>::Node,
    ) -> Result<Option<String>, DocumentError>;

    // Provided methods
    fn descend<'n>(
        &self,
        node: &'n <<Self as Backend>::Document as Editable>::Node,
        key: &str,
        _path: &[String],
    ) -> Result<Option<&'n <<Self as Backend>::Document as Editable>::Node>, DocumentError> { ... }
    fn explain(
        &self,
        _current: &Self::Document,
        error: MergeError,
    ) -> DocumentError { ... }
    fn read_string(
        &self,
        source: &str,
        path: &[String],
    ) -> Result<Option<String>, DocumentError> { ... }
    fn reconcile(
        &self,
        desired: &Annotated,
        source: &Source<'_>,
        ownership: &Ownership,
    ) -> Result<Vec<u8>, DocumentError> { ... }
}
Expand description

A structured format that can be parsed, edited in place, and rendered.

Required Associated Types§

Required Methods§

Source

fn build(&self, desired: &Annotated) -> Result<Self::Document, DocumentError>

Build the desired document from its annotated value.

§Errors

Returns an error when the value cannot be represented in this format.

Source

fn finish( &self, current: &mut Self::Document, desired: &Self::Document, existing: Existing, )

Adjust the merged document before it is rendered.

Source

fn format(&self) -> Format

The format this backend reads and writes.

Source

fn parse(&self, source: &str) -> Result<Self::Document, DocumentError>

Parse an existing source document.

§Errors

Returns an error when the source is malformed.

Source

fn string_leaf( &self, node: &<<Self as Backend>::Document as Editable>::Node, ) -> Result<Option<String>, DocumentError>

The text of node when it is a string, None for any other kind of value.

§Errors

Returns an error when the string cannot be decoded.

Provided Methods§

Source

fn descend<'n>( &self, node: &'n <<Self as Backend>::Document as Editable>::Node, key: &str, _path: &[String], ) -> Result<Option<&'n <<Self as Backend>::Document as Editable>::Node>, DocumentError>

The child key of node, which sits at path. Backends fail here when a node on the way cannot be read through.

§Errors

Returns an error when node cannot be descended into.

Source

fn explain(&self, _current: &Self::Document, error: MergeError) -> DocumentError

The error for a merge that failed against current. Backends can name a cause more precisely than the generic conflict.

Source

fn read_string( &self, source: &str, path: &[String], ) -> Result<Option<String>, DocumentError>

The string at path in source, or None when a key on the way is absent.

§Errors

Returns an error for malformed source, and a not-a-string error when the value at path is not a string.

Source

fn reconcile( &self, desired: &Annotated, source: &Source<'_>, ownership: &Ownership, ) -> Result<Vec<u8>, DocumentError>

Reconcile a desired value against the current source.

When the whole document is owned, the source holds no text and cannot affect the output.

§Errors

Returns an error for malformed source, values the format cannot represent, or an incompatible merge.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§