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§
Sourcefn build(&self, desired: &Annotated) -> Result<Self::Document, DocumentError>
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.
Sourcefn finish(
&self,
current: &mut Self::Document,
desired: &Self::Document,
existing: Existing,
)
fn finish( &self, current: &mut Self::Document, desired: &Self::Document, existing: Existing, )
Adjust the merged document before it is rendered.
Provided Methods§
Sourcefn 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 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.
Sourcefn explain(&self, _current: &Self::Document, error: MergeError) -> DocumentError
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.
Sourcefn read_string(
&self,
source: &str,
path: &[String],
) -> Result<Option<String>, DocumentError>
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.
Sourcefn reconcile(
&self,
desired: &Annotated,
source: &Source<'_>,
ownership: &Ownership,
) -> Result<Vec<u8>, DocumentError>
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".