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>
impl<T> AnyCollection<T>
Sourcepub fn new<C>(collection: C) -> Selfwhere
C: Collection<Item = T>,
pub fn new<C>(collection: C) -> Selfwhere
C: Collection<Item = T>,
Creates a new AnyCollection from any type that implements Collection.
Sourcepub fn get(&self, index: usize) -> Option<T>
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>.
Sourcepub fn watch(
&self,
range: impl RangeBounds<usize>,
watcher: impl for<'a> Fn(Context<&'a [T]>) + 'static,
) -> BoxWatcherGuard
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more