Skip to main content

Deque

Struct Deque 

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

Append-only deque which ensures the elements pushed into it never move. Allocates chunks in doubling capacities.

Implementations§

Source§

impl<T> Deque<T>

Source

pub fn new() -> Self

Source

pub fn push(&mut self, val: T) -> &T

Append an element to the deque and return a reference to it. The element will not move after it is allocated.

Source

pub fn len(&self) -> usize

Return the number of elements that have been appended to the deque.

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Iterator over every element of the deque.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Iterator over every element of the deque.

Source

pub fn truncate(&mut self, len: usize)

Truncate the deque to len elements, dropping every element at index >= len and freeing fully-vacated trailing chunks. Surviving elements never move (only trailing elements/chunks are dropped), so references to them remain valid. Used by the AST arena’s AllocationScope (bump-allocator save/restore semantics, mirroring the C++ BumpPtrAllocator::pushScope/popScope, hermes/Support/Allocator.h:500).

Source

pub fn iter_from(&self, index: usize) -> impl Iterator<Item = &T>

Iterate over the elements starting at index. Positions by chunk arithmetic (a handful of chunk-boundary comparisons; skipped elements are not walked), so iterating a suffix is O(suffix). An index at or past len() yields an empty iterator.

Trait Implementations§

Source§

impl<T: Debug> Debug for Deque<T>

Source§

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

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

impl<T> Default for Deque<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> HeapSize for Deque<T>

Source§

fn heap_size(&self) -> usize

Return the size of the heap allocated memory for the type, in bytes.

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