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>where
T: for<'a> ReadXDR<'a>,
impl<T> Value<T>where
T: for<'a> ReadXDR<'a>,
Sourcepub fn get(&self) -> T
pub fn get(&self) -> T
Deserialize and return the stored value. Aborts if the key does not exist.
Sourcepub fn try_get(&self) -> Result<T, LibraryExn>
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,
impl<T> Value<T>where
T: WriteXDR,
Sourcepub fn set_exclusive(&mut self, value: &T)
pub fn set_exclusive(&mut self, value: &T)
Serialize and store the value with an exclusive lock.
Sourcepub fn try_set_exclusive(&mut self, value: &T) -> Result<(), LibraryExn>
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.
Trait Implementations§
Source§impl<T> Deletable for Value<T>
impl<T> Deletable for Value<T>
Source§fn delete_internal(&mut self, exclusive: bool)
fn delete_internal(&mut self, exclusive: bool)
Source§fn delete_exclusive(&mut self)
fn delete_exclusive(&mut self)
Source§impl<T> Flaggable for Value<T>
impl<T> Flaggable for Value<T>
Source§fn flags(&self) -> StorageFlags
fn flags(&self) -> StorageFlags
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)
fn set_flags(&mut self, flags: StorageFlags)
flags (a bitwise OR) to the key’s storage flags. Later writes
through any handle keep them. Read more