pub struct Object<'a> { /* private fields */ }Expand description
A versioned record reached through Context::as_object.
Object is the entry point for record-based deserialization: it exposes the schema
version via Object::version, the user keys via Object::keys, typed field
extraction via Object::field (and the load_fields!
macro), and side-car artifact access via Object::read.
Implementations§
Source§impl<'a> Object<'a>
impl<'a> Object<'a>
Sourcepub fn keys(&self) -> Keys<'_, 'a> ⓘ
pub fn keys(&self) -> Keys<'_, 'a> ⓘ
Iterate over the user keys of this record. Reserved keys ($version,
$handle) are tracked separately and never appear here.
Sourcepub fn single_key(&self) -> Result<&str>
pub fn single_key(&self) -> Result<&str>
Return the sole user key of this record, used by enum loaders to dispatch
to a variant arm. Errors with a recoverable error::Kind::TypeMismatch
if the record has zero or multiple user keys (i.e. the wire shape does
not look like an enum).
Sourcepub fn child(&self, key: &str) -> Result<Context<'a>>
pub fn child(&self, key: &str) -> Result<Context<'a>>
Descend into the raw Context for key, without imposing a type.
Useful for enum variants whose payload is itself an Object, an array,
or any other save::Value. Returns error::Kind::MissingField when
the key is absent.
Sourcepub fn field<T>(&self, key: &str) -> Result<T>where
T: Loadable<'a>,
pub fn field<T>(&self, key: &str) -> Result<T>where
T: Loadable<'a>,
Extract the value under key and deserialize it into a T.
This is the typed counterpart to Object::child and the primitive used by the
load_fields! macro.
§Errors
Returns error::Kind::MissingField if the key is absent. Errors raised by
T::load (e.g. error::Kind::TypeMismatch) are propagated unchanged.
Sourcepub fn read(&self, handle: &Handle) -> Result<Reader<'_>>
pub fn read(&self, handle: &Handle) -> Result<Reader<'_>>
Open the side-car artifact identified by handle for reading.
The handle must have been previously written through the matching
save::Context::write call and embedded in this
record. Returns error::Kind::MissingFile if the file is not registered in the
manifest or if the handle attempts to escape the manifest directory.