pub trait IntoEure<T = Self>: Sized {
type Error: From<WriteError>;
// Required method
fn write(value: T, c: &mut DocumentConstructor) -> Result<(), Self::Error>;
// Provided method
fn write_flatten(
value: T,
rec: &mut RecordWriter<'_>,
) -> Result<(), Self::Error> { ... }
}Expand description
Trait for writing Rust types to Eure documents.
Types implementing this trait can be serialized into EureDocument
via DocumentConstructor.
The generic parameter T defaults to Self, allowing remote type support
via marker types:
IntoEure(same asIntoEure<Self>) - standard implementationIntoEure<RemoteType>- marker type implements writing for a remote type
§Examples
Standard implementation:
ⓘ
impl IntoEure for User {
type Error = WriteError;
fn write(value: User, c: &mut DocumentConstructor) -> Result<(), Self::Error> {
c.record(|rec| {
rec.field("name", value.name)?;
rec.field_optional("age", value.age)?;
Ok::<(), WriteError>(())
})
}
}Remote type support via marker:
ⓘ
impl IntoEure<std::time::Duration> for DurationDef {
type Error = WriteError;
fn write(value: std::time::Duration, c: &mut DocumentConstructor) -> Result<(), Self::Error> {
c.record(|rec| {
rec.field("secs", value.as_secs())?;
rec.field("nanos", value.subsec_nanos())?;
Ok::<(), WriteError>(())
})
}
}Required Associated Types§
Sourcetype Error: From<WriteError>
type Error: From<WriteError>
The error type returned when writing.
This must be able to represent WriteError so document-constructor
failures can be propagated through custom user errors.
Required Methods§
Provided Methods§
Sourcefn write_flatten(
value: T,
rec: &mut RecordWriter<'_>,
) -> Result<(), Self::Error>
fn write_flatten( value: T, rec: &mut RecordWriter<'_>, ) -> Result<(), Self::Error>
Write a value as flattened record fields.
The default implementation returns a runtime error. Types that are
record-like (e.g. named structs, map-like containers) should override
this to emit fields into rec.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".