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.
When ext_mode is true, field writes are redirected to extension writes.
This is used by flatten_ext to write fields as extensions.
§Example
c.record(|rec| {
rec.field("name", "Alice")?;
rec.field_optional("age", Some(30))?;
Ok(())
})?;Implementations§
Source§impl<'a> RecordWriter<'a>
impl<'a> RecordWriter<'a>
Sourcepub fn new_with_ext_mode(
constructor: &'a mut DocumentConstructor,
ext_mode: bool,
) -> Self
pub fn new_with_ext_mode( constructor: &'a mut DocumentConstructor, ext_mode: bool, ) -> Self
Create a new RecordWriter with the specified ext_mode.
This is primarily used by generated derive code that needs to write flattened extension fields onto an existing node.
Sourcepub fn field_via<M, T>(&mut self, name: &str, value: T) -> Result<(), M::Error>where
M: IntoEure<T>,
pub fn field_via<M, T>(&mut self, name: &str, value: T) -> Result<(), M::Error>where
M: IntoEure<T>,
Write a required field using a marker type.
This enables writing types from external crates that can’t implement
IntoEure directly due to Rust’s orphan rule.
In ext_mode, this redirects to an extension write via the marker type.
§Example
// DurationDef implements IntoEure<std::time::Duration>
rec.field_via::<DurationDef, _>("timeout", duration)?;Sourcepub fn field_optional<T: IntoEure>(
&mut self,
name: &str,
value: Option<T>,
) -> Result<(), T::Error>
pub fn field_optional<T: IntoEure>( &mut self, name: &str, value: Option<T>, ) -> Result<(), T::Error>
Sourcepub fn field_with<F, T>(&mut self, name: &str, f: F) -> Result<T, WriteError>
pub fn field_with<F, T>(&mut self, name: &str, f: F) -> Result<T, WriteError>
Sourcepub fn field_with_optional<T, F, R>(
&mut self,
name: &str,
value: Option<T>,
f: F,
) -> Result<Option<R>, WriteError>
pub fn field_with_optional<T, F, R>( &mut self, name: &str, value: Option<T>, f: F, ) -> Result<Option<R>, WriteError>
Sourcepub fn constructor(&mut self) -> &mut DocumentConstructor
pub fn constructor(&mut self) -> &mut DocumentConstructor
Get a mutable reference to the underlying DocumentConstructor.
Useful for advanced use cases that need direct access.