Struct relm4::factory::collections::DynamicIndex
source · pub struct DynamicIndex { /* private fields */ }
Expand description
A dynamic index that updates automatically when items are shifted inside a Factory
.
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
to still 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
or even better as WeakDynamicIndex
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 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
.
Panics
Sending a DynamicIndex
to a different thread and accessing it will panic.
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
and might change after each update function.
sourcepub fn downgrade(&self) -> WeakDynamicIndex
pub fn downgrade(&self) -> WeakDynamicIndex
Creates a WeakDynamicIndex
for sending in messages.
Trait Implementations§
source§impl Clone for DynamicIndex
impl Clone for DynamicIndex
source§impl Debug for DynamicIndex
impl Debug for DynamicIndex
source§impl PartialEq<DynamicIndex> for DynamicIndex
impl PartialEq<DynamicIndex> for DynamicIndex
source§fn eq(&self, other: &DynamicIndex) -> bool
fn eq(&self, other: &DynamicIndex) -> bool
self
and other
values to be equal, and is used
by ==
.