Struct relm4::prelude::DynamicIndex
source · pub struct DynamicIndex { /* private fields */ }
Expand description
A dynamic index that updates automatically when items are shifted inside a factory container.
For example a FactoryVecDeque
has an insert
method that allows users to insert data at arbitrary positions.
If we insert at the front all following widgets will be moved by one which would
invalidate their indices.
To allow widgets in a factory container to send messages with valid indices
this type ensures that the indices is always up to date.
Never send an index as usize
but always as DynamicIndex
to the update function because messages can be queued up and stale by the time they are handled.
DynamicIndex
is a smart pointer so cloning will work similar to std::rc::Rc
and will create
a pointer to the same data.
In short: only call current_index
from the update function
where you actually need the index as usize
.
Implementations§
source§impl DynamicIndex
impl DynamicIndex
sourcepub fn current_index(&self) -> usize
pub fn current_index(&self) -> usize
Get the current index number.
This value is updated by the factory container and might change after each update function.