AnyCollection

Struct AnyCollection 

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

A type-erased wrapper for any collection that implements Collection.

This allows storing collections of different concrete types in the same container while preserving the ability to observe them through the Collection interface. Items are returned as Box<dyn Any> to allow runtime type checking.

Implementations§

Source§

impl<T> AnyCollection<T>

Source

pub fn new<C>(collection: C) -> Self
where C: Collection<Item = T>,

Creates a new AnyCollection from any type that implements Collection.

Source

pub fn get(&self, index: usize) -> Option<T>

Gets an item from the collection at the specified index.

Returns None if the index is out of bounds. The returned item is type-erased as Box<dyn Any>.

Source

pub fn len(&self) -> usize

Returns the number of items in the collection.

Source

pub fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Source

pub fn watch( &self, range: impl RangeBounds<usize>, watcher: impl for<'a> Fn(Context<&'a [T]>) + 'static, ) -> BoxWatcherGuard

Registers a watcher for changes in the specified range of the collection.

The watcher receives a Vec<Box<dyn Any>> of items. Returns a type-erased guard that will unregister the watcher when dropped.

Trait Implementations§

Source§

impl<T> Debug for AnyCollection<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AnyCollection<T>

§

impl<T> !RefUnwindSafe for AnyCollection<T>

§

impl<T> !Send for AnyCollection<T>

§

impl<T> !Sync for AnyCollection<T>

§

impl<T> Unpin for AnyCollection<T>

§

impl<T> !UnwindSafe for AnyCollection<T>

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.