ferroui_dynamic_data/binding/i_index_aware.rs
1//! `IIndexAware` (`Binding/IIndexAware.cs`).
2
3use std::rc::Rc;
4
5/// An item that knows its index in a sorted collection (`IIndexAware`), which `UpdateIndex` sets.
6///
7/// Deviation (DEVIATIONS.md, DynamicData): the setter takes `&self`, as the items are shared
8/// (`Rc`) and keep the index in a `Cell`; the index is a `usize`.
9pub trait IIndexAware {
10 /// The index (`Index`).
11 fn index(&self) -> usize;
12 /// Sets the index (`Index`).
13 fn set_index(&self, index: usize);
14}
15
16impl<X: IIndexAware + ?Sized> IIndexAware for Rc<X> {
17 fn index(&self) -> usize {
18 (**self).index()
19 }
20
21 fn set_index(&self, index: usize) {
22 (**self).set_index(index);
23 }
24}