Skip to main content

DynList

Struct DynList 

Source
pub struct DynList<T, Typ = DoubleLinked>
where T: Pointee<Metadata = DynMetadata<T>> + ?Sized, Typ: ListType<T>,
{ /* private fields */ }
Expand description

A list of objects that all implement a trait.

See the crate documentation for more info.

Implementations§

Source§

impl<T, Typ> DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + ?Sized, Typ: ListType<T>,

Source

pub fn new() -> Self

Creates an empty list.

Does not allocate.

Source

pub fn len(&self) -> usize

Gets the number of items in the list.

Source

pub fn is_empty(&self) -> bool

Checks if the list is empty.

Source

pub unsafe fn push_ptr(&mut self, value: *mut T)

Moves a dyn trait from a pointer and pushes it to the end of the list.

This moves the data out of the passed-in pointer, rendering it no longer dereferenceable.

§Safety

The pointer must be dereferenceable.

Source

pub fn push_boxed(&mut self, value: Box<T>)

Moves a dyn trait out of a box and pushes it to the end of the list.

In addition to adding items from boxes, it also does not require the dyn trait object to implement FromImpl.

Source

pub fn push<U>(&mut self, value: U)
where T: FromImpl<U>,

Pushes an element onto the list.

This requires that the trait object implements FromImpl for U. On nightly, it is implemented for all trait implementations, but on stable requires using the impl_from_impl macro on the trait.

See also Self::push_boxed and Self::push_ptr.

Source

pub fn extend_from_other<Typ2>(&mut self, other: DynList<T, Typ2>)
where Typ2: ListType<T>,

Moves all items from another DynList into this one, adding them to the end in order.

Source

pub fn clear(&mut self)

Clears the list, removing all elements.

The list capacity is retained.

Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity to hold exactly what is stored in the list.

Source

pub fn iter<'a>(&'a self) -> Iter<'a, T, Typ> ⓘ

Iterates through items in this list

Source

pub fn iter_mut<'a>(&'a mut self) -> IterMut<'a, T, Typ> ⓘ

Iterates through items in this list mutably.

Note: if using with dyn Any, review Rust’s advice about calling its methods! You will need to derference the item before calling a method from Any.

Source

pub fn into_ptrs_iter(self) -> IntoPtrsIter<T, Typ> ⓘ

Move elements out of the list, yielding pointers to them.

The pointers are valid until the iterator is dropped, at which point they are all deallocated.

Yielded pointers will not have their contents dropped, so it is safe to move the data out of them. Any remaining unyielded pointers will have their contents dropped once the iterator is dropped.

Source

pub fn into_box_iter(self) -> IntoBoxedIter<T, Typ> ⓘ

Moves elements out of the list, moving them into boxes.

Source

pub fn cursor<'a>(&'a mut self) -> Option<Cursor<'a, T, Typ>>

Creates a cursor located at the beginning of the list.

Unlike an iterator, the Cursor is lending, but provides the iters::Cursor::drop_after method for dropping a section of the list.

Returns None if the list is empty.

Source§

impl<T, Typ> DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + ?Sized, Typ: ListTypeRev<T>,

Source

pub fn cursor_end<'a>(&'a mut self) -> Option<Cursor<'a, T, Typ>>

Creates a cursor located at the end of the list.

Returns None if the list is empty.

Trait Implementations§

Source§

impl<T, Typ> Debug for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + Debug + ?Sized, Typ: ListType<T>,

Source§

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

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

impl<T, Typ> Default for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + ?Sized, Typ: ListType<T>,

Source§

fn default() -> Self

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

impl<T, Typ> Drop for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + ?Sized, Typ: ListType<T>,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T, Typ> Eq for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + Eq + ?Sized, Typ: ListType<T>,

Source§

impl<U, T, Typ> Extend<U> for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + FromImpl<U> + ?Sized, Typ: ListType<T>,

Source§

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

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: T)

🔬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, Typ1, U, Typ2> PartialEq<DynList<U, Typ2>> for DynList<T, Typ1>
where T: Pointee<Metadata = DynMetadata<T>> + PartialEq<U> + ?Sized, U: Pointee<Metadata = DynMetadata<U>> + ?Sized, Typ1: ListType<T>, Typ2: ListType<U>,

Source§

fn eq(&self, other: &DynList<U, Typ2>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T, Typ> Send for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + Send + ?Sized, Typ: ListType<T> + Send,

Source§

impl<T, Typ> Sync for DynList<T, Typ>
where T: Pointee<Metadata = DynMetadata<T>> + Sync + ?Sized, Typ: ListType<T> + Sync,

Auto Trait Implementations§

§

impl<T, Typ> Freeze for DynList<T, Typ>
where Typ: Freeze, PhantomData<(<T as Pointee>::Metadata, T)>: Freeze, T: ?Sized,

§

impl<T, Typ> RefUnwindSafe for DynList<T, Typ>
where Typ: RefUnwindSafe, PhantomData<(<T as Pointee>::Metadata, T)>: RefUnwindSafe, T: ?Sized,

§

impl<T, Typ> Unpin for DynList<T, Typ>
where Typ: Unpin, PhantomData<(<T as Pointee>::Metadata, T)>: Unpin, T: ?Sized,

§

impl<T, Typ> UnsafeUnpin for DynList<T, Typ>
where Typ: UnsafeUnpin, PhantomData<(<T as Pointee>::Metadata, T)>: UnsafeUnpin, T: ?Sized,

§

impl<T, Typ> UnwindSafe for DynList<T, Typ>
where Typ: UnwindSafe, PhantomData<(<T as Pointee>::Metadata, T)>: UnwindSafe, T: ?Sized,

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

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.