Constant

Struct Constant 

Source
pub struct Constant<C>
where C: Collection, C::Item: View,
{ /* private fields */ }
Expand description

A statically sized collection that never changes, removes, or adds items.

Constant wraps a collection and provides a stable view collection where elements are identified by their index position. This is useful for static lists of views that don’t need to be updated or reordered.

Implementations§

Source§

impl<C> Constant<C>
where C: Collection, C::Item: View,

Source

pub const fn new(value: C) -> Self

Creates a new Constant collection from the provided collection.

§Parameters
  • value - The underlying collection to be wrapped as a constant view collection
§Returns

A new Constant instance containing the provided collection

Trait Implementations§

Source§

impl<C> Clone for Constant<C>
where C: Collection + Clone, C::Item: View,

Source§

fn clone(&self) -> Constant<C>

Returns a duplicate 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<C> Collection for Constant<C>
where C: Collection + Clone, C::Item: View,

Source§

type Item = SelfId<usize>

The type of items stored in the collection.
Source§

type Guard = ()

The type of guard returned when registering a watcher.
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. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.
Source§

impl<C> Debug for Constant<C>
where C: Collection + Debug, C::Item: View,

Source§

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

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

impl<V> Views for Constant<V>
where V: Collection + Clone, V::Item: View,

Source§

type Id = SelfId<usize>

The type of unique identifier for items in the collection. Must implement Hash and Ord to ensure uniqueness and ordering.
Source§

type Guard = ()

The type of guard returned when registering a watcher.
Source§

type View = <V as Collection>::Item

The view type that this collection produces for each element.
Source§

fn len(&self) -> usize

Returns the number of items in the collection.
Source§

fn get_id(&self, index: usize) -> Option<Self::Id>

Returns the unique identifier for the item at the specified index, or None if out of bounds.
Source§

fn get_view(&self, index: usize) -> Option<Self::View>

Returns the view at the specified index, or None if the index is out of bounds.
Source§

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

Registers a watcher for changes in the specified range of the collection. Read more
Source§

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Auto Trait Implementations§

§

impl<C> Freeze for Constant<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Constant<C>
where C: RefUnwindSafe,

§

impl<C> Send for Constant<C>
where C: Send,

§

impl<C> Sync for Constant<C>
where C: Sync,

§

impl<C> Unpin for Constant<C>
where C: Unpin,

§

impl<C> UnwindSafe for Constant<C>
where C: UnwindSafe,

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> IdentifiableExt for T

Source§

fn use_id<F, Id>(self, f: F) -> UseId<Self, F>
where F: Fn(&Self) -> Id, Id: Ord + Hash,

Wraps the value in a UseId with the provided identification function.
Source§

fn self_id(self) -> SelfId<Self>

Wraps the value in a SelfId, making the value serve as its own identifier.
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.
Source§

impl<T> ViewsExt for T
where T: Views,

Source§

fn map<F, V>(self, f: F) -> Map<Self, F>
where Self: Sized, F: Fn(Self::View) -> V, V: View,

Transforms each view in the collection using the provided mapping function. Read more
Source§

fn erase(self) -> AnyViews<AnyView>
where Self: 'static + Sized,

Erases the specific type of the view collection, returning a type-erased AnyViews.