Skip to main content

ListDataSource

Trait ListDataSource 

Source
pub trait ListDataSource: 'static {
    type Item: 'static;
    type Key: ItemKey;

Show 16 methods // Required methods fn len(&self) -> usize; fn with_item<R>( &self, index: usize, f: impl FnOnce(&Self::Item) -> R, ) -> Option<R>; fn observe_changes( &self, f: impl Fn(&DataChange) + 'static, ) -> ObserverHandle; // Provided methods fn is_empty(&self) -> bool { ... } fn key_at(&self, _index: usize) -> Option<Self::Key> { ... } fn index_of(&self, _key: &Self::Key) -> Option<usize> { ... } fn first_changed_index(&self) -> Option<usize> { ... } fn drag(&self, _key: &Self::Key) -> DragEligibility { ... } fn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse { ... } fn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool { ... } fn reorder_within( &self, sources: &[Self::Key], target: &Self::Key, position: DropPosition, ) -> bool { ... } fn on_drag_out(&self, _key: &Self::Key) { ... } fn row_state(&self, _index: usize) -> RowState { ... } fn request_window(&self, _range: Range<usize>) { ... } fn can_fetch_more(&self) -> bool { ... } fn fetch_more(&self) { ... }
}
Expand description

A data source for a flat collection viewed by ListView, TableView, and GridView.

The trait separates the read interface (len, with_item) from the capability protocol: identity (key_at/index_of), drag-and-drop validation (drag/can_accept/accept_drop/on_drag_out), and lazy loading (row_state/request_window/can_fetch_more/fetch_more). All capability methods have inert defaults, so a minimal implementation only needs len, with_item, and observe_changes.

Required Associated Types§

Source

type Item: 'static

The item type exposed by this data source.

Source

type Key: ItemKey

The stable per-row identity. In-memory ListModel uses usize (the index); external sources use their own domain key so keyed selection / DnD survive reorders without a mirror model.

Required Methods§

Source

fn len(&self) -> usize

Number of rows (the total, including not-yet-loaded ones for a windowed source — the scrollbar needs it).

Source

fn with_item<R>( &self, index: usize, f: impl FnOnce(&Self::Item) -> R, ) -> Option<R>

Access the item at index via a callback. Returns None for an out-of-bounds index OR an in-bounds index whose data is still Loading (see row_state).

Source

fn observe_changes(&self, f: impl Fn(&DataChange) + 'static) -> ObserverHandle

Register an observer that is called on every mutation; dropping the returned [ObserverHandle] unregisters the callback automatically.

Provided Methods§

Source

fn is_empty(&self) -> bool

Whether the source is empty.

Source

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

The stable key of the row at index. Default None (no identity); sources that support keyed selection / DnD override it.

Source

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

The index of a key, if currently present. Default None.

Source

fn first_changed_index(&self) -> Option<usize>

First index whose content may differ after the change just delivered — rows 0..index are unchanged. None means unknown (full change).

Source

fn drag(&self, _key: &Self::Key) -> DragEligibility

Whether the row may begin a drag (the transferable gate).

Source

fn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse

Whether a hovered drop is permitted (and where) — the pre-commit verdict.

Source

fn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool

Apply a committed drop. Returns whether it was applied.

Source

fn reorder_within( &self, sources: &[Self::Key], target: &Self::Key, position: DropPosition, ) -> bool

Reorder a whole set of this source’s OWN rows so they land contiguously at a drop gap — the multi-row same-view reorder commit. sources are the dragged rows’ keys in the origin’s visible order; target / position name the drop gap. Returns whether anything moved.

The default moves them one at a time, re-anchoring each after the previous so they stay contiguous and keep their relative order — correct for a source with stable keys. ListModel, whose key is the index (so a single move renumbers everything), overrides this with a direct block move; a single-row drag needs neither and just falls through to one accept_drop.

Source

fn on_drag_out(&self, _key: &Self::Key)

Called on the origin source after one of its rows was accepted by a different view (source-side completion). Shared/command-backed sources no-op this; independent models use it to drop the moved row.

Source

fn row_state(&self, _index: usize) -> RowState

Whether the row at index is loaded.

Source

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

Nudge the source to load the given range (the view calls this each build with its visible + buffer window).

Source

fn can_fetch_more(&self) -> bool

Whether more rows can be appended (infinite scroll).

Source

fn fetch_more(&self)

Fetch the next page (append-only growth).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: 'static> ListDataSource for ListModel<T>

ListModel is the built-in fully-resident, in-memory ListDataSource. Identity is positional (Key = usize); a SameView drop reorders via move_item. Into and Foreign drops are rejected (a flat list does not nest, and a bare model knows no foreign payloads).

Source§

impl<T: 'static> ListDataSource for SortFilterListModel<T>