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§
Required Methods§
Sourcefn len(&self) -> usize
fn len(&self) -> usize
Number of rows (the total, including not-yet-loaded ones for a windowed source — the scrollbar needs it).
Sourcefn with_item<R>(
&self,
index: usize,
f: impl FnOnce(&Self::Item) -> R,
) -> Option<R>
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).
Sourcefn observe_changes(&self, f: impl Fn(&DataChange) + 'static) -> ObserverHandle
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§
Sourcefn key_at(&self, _index: usize) -> Option<Self::Key>
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.
Sourcefn index_of(&self, _key: &Self::Key) -> Option<usize>
fn index_of(&self, _key: &Self::Key) -> Option<usize>
The index of a key, if currently present. Default None.
Sourcefn first_changed_index(&self) -> Option<usize>
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).
Sourcefn drag(&self, _key: &Self::Key) -> DragEligibility
fn drag(&self, _key: &Self::Key) -> DragEligibility
Whether the row may begin a drag (the transferable gate).
Sourcefn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse
fn can_accept(&self, _query: &DropQuery<'_, Self::Key>) -> DropResponse
Whether a hovered drop is permitted (and where) — the pre-commit verdict.
Sourcefn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool
fn accept_drop(&self, _commit: DropCommit<'_, Self::Key>) -> bool
Apply a committed drop. Returns whether it was applied.
Sourcefn reorder_within(
&self,
sources: &[Self::Key],
target: &Self::Key,
position: DropPosition,
) -> bool
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.
Sourcefn on_drag_out(&self, _key: &Self::Key)
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.
Sourcefn request_window(&self, _range: Range<usize>)
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).
Sourcefn can_fetch_more(&self) -> bool
fn can_fetch_more(&self) -> bool
Whether more rows can be appended (infinite scroll).
Sourcefn fetch_more(&self)
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).
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).