Skip to main content

ListModel

Trait ListModel 

pub trait ListModel {
    type Key: Clone + Eq + Hash + 'static;

    // Required methods
    fn len(&self) -> usize;
    fn key_at(&self, index: usize) -> Option<Self::Key>;
    fn index_of(&self, key: &Self::Key) -> Option<usize>;

    // Provided methods
    fn is_empty(&self) -> bool { ... }
    fn row_state(&self, _index: usize) -> ListRowState<'_> { ... }
    fn request_range(&mut self, _range: Range<usize>) { ... }
    fn poll_changed(&mut self) -> bool { ... }
    fn poll_changes(&mut self) -> Vec<ListModelChange<Self::Key>> { ... }
    fn needs_poll(&self) -> bool { ... }
}
Expand description

Random-access collection contract for VirtualList. Keys must be unique and stable while an item represents the same logical entity.

Required Associated Types§

type Key: Clone + Eq + Hash + 'static

Required Methods§

fn len(&self) -> usize

fn key_at(&self, index: usize) -> Option<Self::Key>

fn index_of(&self, key: &Self::Key) -> Option<usize>

Provided Methods§

fn is_empty(&self) -> bool

fn row_state(&self, _index: usize) -> ListRowState<'_>

Current state of a logical row. Paged models can keep stable keys and geometry while their data moves through loading, ready, and error.

fn request_range(&mut self, _range: Range<usize>)

Opportunity to enqueue work for the visible window plus overscan.

fn poll_changed(&mut self) -> bool

Drain a model-owned invalidation wakeup. Return true after logical order, count, key, or row-state changes. Use VirtualList::invalidate_rows as well when ready delegate content changed without changing state.

fn poll_changes(&mut self) -> Vec<ListModelChange<Self::Key>>

Drain specific model changes. Prefer this to Self::poll_changed when an asynchronous source can identify its batch: stable delegates then survive structural changes and only named content rows rebuild.

fn needs_poll(&self) -> bool

Keep scheduling frames while Self::poll_changed or Self::poll_changes may observe an in-flight asynchronous source.

Implementors§

§

impl<T, K> ListModel for VecListModel<T, K>
where K: Clone + Eq + Hash + 'static,

§

type Key = K