Skip to main content

Deque

Struct 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

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

Sets the value at the given position in the queue. Returns [StdError::NotFound] if 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> UnsafeUnpin for Deque<T>

§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V