Skip to main content

Value

Struct Value 

Source
pub struct Value<T> { /* private fields */ }
Expand description

A typed storage slot for serialized values.

Value<T> is a handle to a storage location that holds a serialized T. All operations are immediate syscalls — no buffering. For in-place modification with auto-flush, use load_mut().

Implementations§

Source§

impl<T> Value<T>

Source

pub fn key(&self) -> &StorageKey

Return this value’s storage key.

Source§

impl<T> Value<T>
where T: for<'a> ReadXDR<'a>,

Source

pub fn get(&self) -> T

Deserialize and return the stored value. Aborts if the key does not exist.

Source

pub fn try_get(&self) -> Result<T, LibraryExn>

Deserialize and return the stored value, reporting failure as Err instead of aborting (the try_ law; see the exn module docs).

The Err is exactly the exception get would have thrown: a missing key is a LibraryExn::Syscall for which is_storage_missing is true — use none_if_missing to treat just that case as an ordinary None. A value that fails to decode as T (or exceeds the no-alloc read buffer — either way, the slot was written by something other than Value<T>::set) is LibraryExn::StorageSerialization; a value of another storage type or any other syscall failure is a LibraryExn::Syscall.

Source§

impl<T> Value<T>
where T: WriteXDR,

Source

pub fn set(&mut self, value: &T)

Serialize and store the value immediately.

Source

pub fn try_set(&mut self, value: &T) -> Result<(), LibraryExn>

Like set, but report failure as Err instead of aborting (the try_ law; see the exn module docs). A value that fails to serialize is LibraryExn::StorageSerialization; a syscall failure is LibraryExn::Syscall. On Err the stored value is unmodified.

Source

pub fn set_exclusive(&mut self, value: &T)

Serialize and store the value with an exclusive lock.

Source

pub fn try_set_exclusive(&mut self, value: &T) -> Result<(), LibraryExn>

Like set_exclusive, but report failure as Err instead of aborting (the try_ law; see the exn module docs). The error contract is try_set’s. On Err the stored value is unmodified and no lock is taken.

Source§

impl<T> Value<T>
where T: WriteXDR + for<'a> ReadXDR<'a>,

Source

pub fn load_mut(&mut self) -> ValueMut<'_, T>

Load the value and return a mutable reference to it.

Trait Implementations§

Source§

impl<T: Debug> Debug for Value<T>

Source§

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

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

impl<T> Deletable for Value<T>

Source§

fn delete_internal(&mut self, exclusive: bool)

Delete storage for this node. Read more
Source§

fn delete(&mut self)

Delete using the keypath’s own locking semantics.
Source§

fn delete_exclusive(&mut self)

Delete, then request an exclusive lock, regardless of keypath flag. Later writes in the transaction keep the lock.
Source§

impl<T> Flaggable for Value<T>

Source§

fn flags(&self) -> StorageFlags

The storage flags the current transaction requests for this key, as seen by the current call frame: ExclusiveLock once an exclusive write or set_flags has asked for it, until clear_flags. A key with no pending write has none.
Source§

fn set_flags(&mut self, flags: StorageFlags)

Adds flags (a bitwise OR) to the key’s storage flags. Later writes through any handle keep them. Read more
Source§

fn clear_flags(&mut self)

Removes every storage flag from the key. Does nothing if no write to it is pending.
Source§

impl<T> From<Keypath> for Value<T>

Source§

fn from(keypath: Keypath) -> Self

Converts to this type from the input type.
Source§

impl<T> StorageType for Value<T>

Auto Trait Implementations§

§

impl<T> Freeze for Value<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for Value<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Value<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for Value<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for Value<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Value<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Value<T>
where PhantomData<fn() -> T>: UnwindSafe,

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> ContractState for T
where T: From<Keypath>,

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> StaticIfNoAlloc for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.