Skip to main content

Record

Struct Record 

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

A map of named Values.

Record is the body of an object in the manifest. On the save side each call to crate::save::Save::save returns one, and Record::into_value wraps it as a Versioned Value::Object ready for insertion into another record; on the load side the same record is read back through crate::load::Object. Keys beginning with $ are reserved for framework metadata (see [crate::is_reserved]).

Implementations§

Source§

impl<'a> Record<'a>

Source

pub fn empty() -> Self

Construct an empty record. Useful for unit enum variants.

Source

pub fn contains_key(&self, key: &str) -> bool

Returns true if a value is registered under key.

Source

pub fn get(&self, key: &str) -> Option<&Value<'a>>

Look up the Value registered under key, if any.

Source

pub fn len(&self) -> usize

Number of (user) keys in this record. Reserved keys ($version, $handle) are tracked elsewhere and never appear here.

Source

pub fn is_empty(&self) -> bool

Returns true if this record has no user keys.

Source

pub fn keys(&self) -> Keys<'_, 'a>

Iterate over the user keys in this record. Order is unspecified.

Source

pub fn insert<K, V>(&mut self, key: K, value: V) -> Result<Option<Value<'a>>>
where K: Into<Cow<'a, str>>, V: Into<Value<'a>>,

Insert value under key.

§Errors

Returns Error if key begins with $, which is reserved for the save/load framework (see [crate::is_reserved]).

Source

pub fn into_value(self, version: Version) -> Value<'a>

Wrap this record as a versioned Value ready for insertion into another record. Use this from enum Save impls to attach the outer type’s version to an inline variant payload.

Source

pub fn into_owned(self) -> Record<'static>

Convert this record into a fully owned Record<'static>, deep-copying borrowed keys and values. See Value::into_owned.

Trait Implementations§

Source§

impl<'a> Debug for Record<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, 'a> Deserialize<'de> for Record<'a>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a> FromIterator<(Cow<'a, str>, Value<'a>)> for Record<'a>

Source§

fn from_iter<I: IntoIterator<Item = (Cow<'a, str>, Value<'a>)>>(itr: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> Serialize for Record<'a>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Record<'a>

§

impl<'a> RefUnwindSafe for Record<'a>

§

impl<'a> Send for Record<'a>

§

impl<'a> Sync for Record<'a>

§

impl<'a> Unpin for Record<'a>

§

impl<'a> UnsafeUnpin for Record<'a>

§

impl<'a> UnwindSafe for Record<'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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.