Collection

Trait Collection 

Source
pub trait Collection: 'static {
    type Item: 'static;
    type Guard: WatcherGuard;

    // Required methods
    fn get(&self, index: usize) -> Option<Self::Item>;
    fn len(&self) -> usize;
    fn watch(
        &self,
        range: impl RangeBounds<usize>,
        watcher: impl for<'a> Fn(Context<&'a [Self::Item]>) + 'static,
    ) -> Self::Guard;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait for collections that can be observed for changes.

This trait provides a common interface for collections that support reactive programming patterns through watchers.

Required Associated Types§

Source

type Item: 'static

The type of items stored in the collection.

Source

type Guard: WatcherGuard

The type of guard returned when registering a watcher.

Required Methods§

Source

fn get(&self, index: usize) -> Option<Self::Item>

Gets an item from the collection at the specified index.

Source

fn len(&self) -> usize

Returns the number of items in the collection.

Source

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

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

Returns a guard that will unregister the watcher when dropped.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<C> Collection for Box<C>
where C: Collection,

Source§

type Item = <C as Collection>::Item

Source§

type Guard = <C as Collection>::Guard

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

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

Source§

impl<C> Collection for Rc<C>
where C: Collection,

Source§

type Item = <C as Collection>::Item

Source§

type Guard = <C as Collection>::Guard

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

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

Source§

impl<T: Clone + 'static> Collection for &'static [T]

Source§

type Item = T

Source§

type Guard = ()

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

fn watch( &self, _range: impl RangeBounds<usize>, _watcher: impl for<'a> Fn(Context<&'a [Self::Item]>) + 'static, ) -> Self::Guard

Source§

impl<T: Clone + 'static> Collection for Rc<[T]>

Source§

type Item = T

Source§

type Guard = ()

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

fn watch( &self, _range: impl RangeBounds<usize>, _watcher: impl for<'a> Fn(Context<&'a [Self::Item]>) + 'static, ) -> Self::Guard

Source§

impl<T: Clone + 'static> Collection for Vec<T>

Source§

type Item = T

Source§

type Guard = ()

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

fn watch( &self, _range: impl RangeBounds<usize>, _watcher: impl for<'a> Fn(Context<&'a [Self::Item]>) + 'static, ) -> Self::Guard

Source§

impl<T: Clone + 'static, const N: usize> Collection for [T; N]

Source§

type Item = T

Source§

type Guard = ()

Source§

fn get(&self, index: usize) -> Option<Self::Item>

Source§

fn len(&self) -> usize

Source§

fn watch( &self, _range: impl RangeBounds<usize>, _watcher: impl for<'a> Fn(Context<&'a [Self::Item]>) + 'static, ) -> Self::Guard

Implementors§