pub trait Emit {
// Required methods
fn emit(&self, ctx: &EmitCtx) -> Result<String>;
fn expected_value(&self) -> Result<Value>;
}Expand description
A value that can be spliced into a document by the auto-formatting mutators.
Implementors provide two halves of one contract:
emit— the YAML spelling to splice, quoted and escaped so that it re-parses to this value atctx’s site.expected_value— the typed value that spelling must load back as.
The mutators check the second against the document after splicing the first, so an implementation whose two halves disagree causes a refusal with the document left unchanged, never a silent corruption.
Implementations ship for str, String, bool, the integer and
float primitives, Value, and any reference to one of those. A
Serialize type is emitted by converting it first:
doc.push_back_value(path, &noyalib::to_value(&my_struct)?).
§Examples
use noyalib::cst::{Emit, EmitCtx};
use noyalib::{FlowStyle, ScalarStyle, Value};
let ctx = EmitCtx::new(ScalarStyle::Plain, FlowStyle::Block, 2, 0);
assert_eq!(42_i64.emit(&ctx).unwrap(), "42");
assert_eq!(42_i64.expected_value().unwrap(), Value::from(42_i64));Required Methods§
Sourcefn emit(&self, ctx: &EmitCtx) -> Result<String>
fn emit(&self, ctx: &EmitCtx) -> Result<String>
The YAML spelling of this value at ctx’s site.
§Errors
Returns Error::Parse when the value has no representation the
emitter can produce for that site (for example a tagged scalar,
whose tag the scalar emitter would drop), and propagates
serializer errors for collections.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".