Struct cw_storage_plus::Deque

source ·
pub struct Deque<T> { /* private fields */ }
Expand description

A deque stores multiple items at the given key. It provides efficient FIFO and LIFO access, as well as direct index access.

It has a maximum capacity of u32::MAX - 1. Make sure to never exceed that number when using this type. If you do, the methods won’t work as intended anymore.

Implementations§

source§

impl<T> Deque<T>

source

pub const fn new(prefix: &'static str) -> Self

Creates a new Deque with the given storage key. This is a constant function only suitable when you have a prefix in the form of a static string slice.

source

pub fn new_dyn(prefix: impl Into<Namespace>) -> Self

Creates a new Deque with the given storage key. Use this if you might need to handle a dynamic string. Otherwise, you should probably prefer Deque::new.

source§

impl<T: Serialize + DeserializeOwned> Deque<T>

source

pub fn push_back(&self, storage: &mut dyn Storage, value: &T) -> StdResult<()>

Adds the given value to the end of the deque

source

pub fn push_front(&self, storage: &mut dyn Storage, value: &T) -> StdResult<()>

Adds the given value to the front of the deque

source

pub fn pop_back(&self, storage: &mut dyn Storage) -> StdResult<Option<T>>

Removes the last element of the deque and returns it

source

pub fn pop_front(&self, storage: &mut dyn Storage) -> StdResult<Option<T>>

Removes the first element of the deque and returns it

source

pub fn front(&self, storage: &dyn Storage) -> StdResult<Option<T>>

Returns the first element of the deque without removing it

source

pub fn back(&self, storage: &dyn Storage) -> StdResult<Option<T>>

Returns the last element of the deque without removing it

source

pub fn len(&self, storage: &dyn Storage) -> StdResult<u32>

Gets the length of the deque.

source

pub fn is_empty(&self, storage: &dyn Storage) -> StdResult<bool>

Returns true if the deque contains no elements.

source

pub fn get(&self, storage: &dyn Storage, pos: u32) -> StdResult<Option<T>>

Returns the value at the given position in the queue or None if the index is out of bounds

source§

impl<T: Serialize + DeserializeOwned> Deque<T>

source

pub fn iter<'a>( &'a self, storage: &'a dyn Storage ) -> StdResult<DequeIter<'a, T>>

Auto Trait Implementations§

§

impl<T> Freeze for Deque<T>

§

impl<T> RefUnwindSafe for Deque<T>
where T: RefUnwindSafe,

§

impl<T> Send for Deque<T>
where T: Send,

§

impl<T> Sync for Deque<T>
where T: Sync,

§

impl<T> Unpin for Deque<T>
where T: Unpin,

§

impl<T> UnwindSafe for Deque<T>
where 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<U> As for U

source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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

§

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.