pub struct Context<'a> { /* private fields */ }Expand description
A cheap, clonable handle threaded through every Save::save impl.
Context exposes one operation — Context::write — for allocating a side-car
artifact. The same context is passed to nested Save impls (typically
via the save_fields! macro), so a single save tree shares
artifact-name bookkeeping. It borrows the backing SaveContext as an object-safe
GetWrite so that the save tree is agnostic to the concrete context type.
Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn write(&self, key: Option<&str>) -> Result<Writer<'_>>
pub fn write(&self, key: Option<&str>) -> Result<Writer<'_>>
Allocate a new side-car artifact in the manifest directory, optionally tagging it
with a human-readable key.
The artifact is named with the count of artifacts written so far (with key, when
Some, appended as a readability hint), so the same key may be passed to
multiple calls. The returned Writer is positioned at offset 0 and implements
std::io::Write / std::io::Seek. Call Writer::finish to obtain a
Handle that may be inserted into a Record.
§Errors
Returns Error if key is Some but not a simple relative file name, or if the
underlying file cannot be created.