RecordWriter

Struct RecordWriter 

Source
pub struct RecordWriter<'a> { /* private fields */ }
Expand description

Helper for writing record (map with string keys) to Eure documents.

Used within the closure passed to DocumentConstructor::record.

§Example

c.record(|rec| {
    rec.field("name", "Alice")?;
    rec.field_optional("age", Some(30))?;
    Ok(())
})?;

Implementations§

Source§

impl<'a> RecordWriter<'a>

Source

pub fn field<T: IntoDocument>( &mut self, name: &str, value: T, ) -> Result<(), WriteError>

Write a required field.

§Example
rec.field("name", "Alice")?;
Source

pub fn field_optional<T: IntoDocument>( &mut self, name: &str, value: Option<T>, ) -> Result<(), WriteError>

Write an optional field. Does nothing if the value is None.

§Example
rec.field_optional("age", self.age)?;
Source

pub fn field_with<F, T>(&mut self, name: &str, f: F) -> Result<T, WriteError>

Write a field using a custom writer closure.

Useful for nested structures that need custom handling.

§Example
rec.field_with("address", |c| {
    c.record(|rec| {
        rec.field("city", "Tokyo")?;
        Ok(())
    })
})?;
Source

pub fn field_with_optional<T, F, R>( &mut self, name: &str, value: Option<T>, f: F, ) -> Result<Option<R>, WriteError>
where F: FnOnce(&mut DocumentConstructor, T) -> Result<R, WriteError>,

Write an optional field using a custom writer closure. Does nothing if the value is None.

§Example
rec.field_with_optional("metadata", self.metadata.as_ref(), |c, meta| {
    meta.write_to(c)
})?;
Source

pub fn constructor(&mut self) -> &mut DocumentConstructor

Get a mutable reference to the underlying DocumentConstructor.

Useful for advanced use cases that need direct access.

Auto Trait Implementations§

§

impl<'a> Freeze for RecordWriter<'a>

§

impl<'a> RefUnwindSafe for RecordWriter<'a>

§

impl<'a> Send for RecordWriter<'a>

§

impl<'a> Sync for RecordWriter<'a>

§

impl<'a> Unpin for RecordWriter<'a>

§

impl<'a> !UnwindSafe for RecordWriter<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.