pub trait IntoEure<T = Self>: Sized {
// Required method
fn write(value: T, c: &mut DocumentConstructor) -> Result<(), WriteError>;
}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 {
fn write(value: User, c: &mut DocumentConstructor) -> Result<(), WriteError> {
c.record(|rec| {
rec.field("name", value.name)?;
rec.field_optional("age", value.age)?;
Ok(())
})
}
}Remote type support via marker:
ⓘ
impl IntoEure<std::time::Duration> for DurationDef {
fn write(value: std::time::Duration, c: &mut DocumentConstructor) -> Result<(), WriteError> {
c.record(|rec| {
rec.field("secs", value.as_secs())?;
rec.field("nanos", value.subsec_nanos())?;
Ok(())
})
}
}Required Methods§
Sourcefn write(value: T, c: &mut DocumentConstructor) -> Result<(), WriteError>
fn write(value: T, c: &mut DocumentConstructor) -> Result<(), WriteError>
Write a value to the current node in the document constructor.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.