once_list2

Struct OnceList

Source
pub struct OnceList<T, A: Allocator = Global> { /* private fields */ }
Expand description

A single linked list which behaves like std::cell::OnceCell, but for multiple values. See the crate document for the examples.

Implementations§

Source§

impl<T> OnceList<T, Global>

Source

pub fn new() -> Self

Creates a new empty OnceList. This method does not allocate.

Source§

impl<T, A: Allocator> OnceList<T, A>

Source

pub fn new_in(alloc: A) -> Self

Creates a new empty OnceList with the given allocator. This method does not allocate.

Source

pub fn len(&self) -> usize

Returns the number of values in the list. This method is O(n).

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty.

Source

pub fn contains(&self, val: &T) -> bool
where T: PartialEq,

Returns true if the list contains the value.

Source

pub fn first(&self) -> Option<&T>

Returns a first value, if it exists.

Source

pub fn first_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the first value, if it exists.

Source

pub fn last(&self) -> Option<&T>

Returns a last value, if it exists. This method is O(n).

Source

pub fn last_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the last value, if it exists. This method is O(n).

Source

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

Returns an iterator over the &T references in the list.

Source

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

Returns an iterator over the &mut T references in the list.

Source

pub fn clear(&mut self)

Clears the list, dropping all values.

Source

pub fn allocator(&self) -> &A

Returns an allocator of this struct.

Source

pub fn remove<P>(&mut self, pred: P) -> Option<T>
where P: FnMut(&T) -> bool,

Find a first value in the list matches the predicate, remove that item from the list, and then returns that value.

Source§

impl<T: Sized, A: Allocator + Clone> OnceList<T, A>

Source

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

Appends a value to the list, and returns the reference to that value.

Note that this method takes &self, not &mut self.

Source

pub fn extend<U: IntoIterator<Item = T>>(&self, iter: U)

An almost same method with the std::iter::Extend::extend, though this method takes &self instead of &mut self.

Trait Implementations§

Source§

impl<T: Clone, A: Clone + Allocator> Clone for OnceList<T, A>

Source§

fn clone(&self) -> OnceList<T, A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, A: Allocator> Debug for OnceList<T, A>

Source§

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

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

impl<T> Default for OnceList<T, Global>

Source§

fn default() -> Self

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

impl<T, A: Allocator + Clone> Extend<T> for OnceList<T, A>

Source§

fn extend<U: IntoIterator<Item = T>>(&mut self, iter: U)

Due to the definition of the Extend trait, this method takes &mut self. Use the OnceList::extend method instead if you want to use &self.

Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> FromIterator<T> for OnceList<T, Global>

Source§

fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, A: Allocator> IntoIterator for OnceList<T, A>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T, A>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, A = Global> !Freeze for OnceList<T, A>

§

impl<T, A = Global> !RefUnwindSafe for OnceList<T, A>

§

impl<T, A> Send for OnceList<T, A>
where A: Send, T: Send,

§

impl<T, A = Global> !Sync for OnceList<T, A>

§

impl<T, A> Unpin for OnceList<T, A>
where A: Unpin,

§

impl<T, A = Global> !UnwindSafe for OnceList<T, A>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.