Skip to main content

Object

Struct Object 

Source
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>

Source

pub fn version(&self) -> Version

The schema Version recorded in the manifest for this object.

Source

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.

Source

pub fn len(&self) -> usize

Number of user keys in this record.

Source

pub fn is_empty(&self) -> bool

Whether this record has no user keys.

Source

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).

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Object<'a>

§

impl<'a> !Send for Object<'a>

§

impl<'a> !Sync for Object<'a>

§

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

§

impl<'a> Freeze for Object<'a>

§

impl<'a> Unpin for Object<'a>

§

impl<'a> UnsafeUnpin for Object<'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.