Skip to main content

ferroui_dynamic_data/list/
source_list_ex.rs

1//! `SourceListEx` (`List/SourceListEx.cs`), with the operators of `ObservableListEx` whose receiver
2//! is a list rather than a sequence of change sets: `DeferUntilLoaded` on `IObservableList`,
3//! `ExpireAfter` and `LimitSizeTo` on `ISourceList`.
4//!
5//! The trait is implemented for every observable list; the methods of a source list require it to
6//! be one, and those that keep the list in a subscription a handle that clones.
7
8use super::{ChangeSet, IObservableList, ISourceList};
9use std::rc::Rc;
10
11/// The operators of lists (`SourceListEx`, and the extension methods of `ObservableListEx` on
12/// `IObservableList` and `ISourceList`).
13pub trait SourceListEx<T: Clone + PartialEq + 'static>: IObservableList<T> {
14    /// The items and their changes, each item converted by `conversion_factory`
15    /// (`Cast(ISourceList<TSource>, Func<TSource, TDestination>)`).
16    fn cast_list<U: Clone + 'static>(&self, conversion_factory: impl Fn(&T) -> U + 'static) -> Rc<dyn ferroui_system::IObservable<ChangeSet<U>>>
17    where
18        Self: ISourceList<T>,
19    {
20        ferroui_reactive::ObservableExt::select(&IObservableList::connect(self), move |changes: ChangeSet<T>| super::transform_change_set(&changes, &conversion_factory))
21    }
22
23    super::ops::defer_until_loaded::defer_until_loaded_source_methods!();
24    super::ops::expire_after::expire_after_source_methods!();
25    super::ops::limit_size_to::limit_size_to_source_methods!();
26}
27
28impl<T: Clone + PartialEq + 'static, L: IObservableList<T> + ?Sized> SourceListEx<T> for L {}