ForEach

Struct ForEach 

Source
pub struct ForEach<C, F, V>
where C: Collection, C::Item: Identifiable, F: Fn(C::Item) -> V, V: View,
{ /* private fields */ }
Expand description

A utility for transforming elements of a collection with a mapping function.

ForEach applies a transformation function to each element of a source collection, producing a new collection with the transformed elements. This is useful for transforming data models into view representations.

Implementations§

Source§

impl<C, F, V> ForEach<C, F, V>
where C: Collection, C::Item: Identifiable, F: Fn(C::Item) -> V, V: View,

Source

pub const fn new(data: C, generator: F) -> Self

Creates a new ForEach transformation with the provided data collection and generator function.

§Parameters
  • data - The source collection containing elements to be transformed
  • generator - A function that transforms elements from the source collection
§Returns

A new ForEach instance that will apply the transformation when accessed

Source

pub fn into_inner(self) -> (C, F)

Consumes the ForEach and returns the original data collection and generator function.

§Returns

A tuple containing the original data collection and generator function

Trait Implementations§

Source§

impl<C, F, V> Clone for ForEach<C, F, V>
where C: Collection + Clone, C::Item: Identifiable, F: Fn(C::Item) -> V + Clone, V: View + Clone,

Source§

fn clone(&self) -> ForEach<C, F, V>

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, F, V> Collection for ForEach<C, F, V>
where C: Collection, C::Item: Identifiable, F: 'static + Fn(C::Item) -> V, V: View,

Source§

type Item = <<C as Collection>::Item as Identifiable>::Id

The type of items stored in the collection.
Source§

type Guard = <C as Collection>::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, F, V> Debug for ForEach<C, F, V>
where C: Collection + Debug, C::Item: Identifiable, F: Fn(C::Item) -> V + Debug, V: View + Debug,

Source§

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

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

impl<C, F, V> Views for ForEach<C, F, V>
where C: Collection, C::Item: Identifiable, F: 'static + Fn(C::Item) -> V, V: View,

Source§

type Id = <<C as Collection>::Item as Identifiable>::Id

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

type View = V

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

type Guard = <C as Collection>::Guard

The type of guard returned when registering a watcher.
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 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::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, F, V> Freeze for ForEach<C, F, V>
where C: Freeze, F: Freeze,

§

impl<C, F, V> RefUnwindSafe for ForEach<C, F, V>

§

impl<C, F, V> Send for ForEach<C, F, V>
where C: Send, F: Send,

§

impl<C, F, V> Sync for ForEach<C, F, V>
where C: Sync, F: Sync,

§

impl<C, F, V> Unpin for ForEach<C, F, V>
where C: Unpin, F: Unpin,

§

impl<C, F, V> UnwindSafe for ForEach<C, F, V>
where C: UnwindSafe, F: 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.