Struct fadroma::storage::IterableStorage
source · [−]pub struct IterableStorage<'a, T: DeserializeOwned + Serialize> { /* private fields */ }
Expand description
Stores items in a way that allows for iterating over them.
Implementations
sourceimpl<'a, T: DeserializeOwned + Serialize> IterableStorage<'a, T>
impl<'a, T: DeserializeOwned + Serialize> IterableStorage<'a, T>
sourcepub fn new(ns: &'a [u8]) -> Self
pub fn new(ns: &'a [u8]) -> Self
Creates an instance for the given namespace.
The following namespaces are reserved by IterableStorage
:
ns
+ “index”ns
+ N - where N is a number
pub fn iter<'storage, S: ReadonlyStorage>(
&self,
storage: &'storage S
) -> StdResult<StorageIterator<'storage, '_, T, S>>
sourcepub fn push(&mut self, storage: &mut impl Storage, value: &T) -> StdResult<u64>
pub fn push(&mut self, storage: &mut impl Storage, value: &T) -> StdResult<u64>
Returns the index at which the item is stored at.
sourcepub fn pop(&mut self, storage: &mut impl Storage) -> StdResult<()>
pub fn pop(&mut self, storage: &mut impl Storage) -> StdResult<()>
Removes the item at the end of the collection.
pub fn get_at(
&self,
storage: &impl ReadonlyStorage,
index: u64
) -> StdResult<Option<T>>
sourcepub fn update_at<F>(
&self,
storage: &mut impl Storage,
index: u64,
update: F
) -> StdResult<bool> where
F: FnOnce(T) -> StdResult<T>,
pub fn update_at<F>(
&self,
storage: &mut impl Storage,
index: u64,
update: F
) -> StdResult<bool> where
F: FnOnce(T) -> StdResult<T>,
Returns true
if the item was updated and false
if no item is stored at that index
.
sourcepub fn swap_remove(
&mut self,
storage: &mut impl Storage,
index: u64
) -> StdResult<Option<T>>
pub fn swap_remove(
&mut self,
storage: &mut impl Storage,
index: u64
) -> StdResult<Option<T>>
Removes the element at the given index. The removed element is replaced by the last element of the storage. Does not preserve ordering. Returns the item that was swapped if such was necessary.
pub fn len(&self, storage: &impl ReadonlyStorage) -> StdResult<u64>
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for IterableStorage<'a, T> where
T: RefUnwindSafe,
impl<'a, T> Send for IterableStorage<'a, T> where
T: Send,
impl<'a, T> Sync for IterableStorage<'a, T> where
T: Sync,
impl<'a, T> Unpin for IterableStorage<'a, T> where
T: Unpin,
impl<'a, T> UnwindSafe for IterableStorage<'a, T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more