Skip to main content

ferroui_dynamic_data/list/
item_change.rs

1//! `ItemChange<T>` (`List/ItemChange.cs`).
2
3/// The change of one item of a list (`ItemChange<T>`).
4#[derive(Clone, Debug, PartialEq, Eq, Hash)]
5pub struct ItemChange<T> {
6    reason: super::ListChangeReason,
7    current: T,
8    previous: Option<T>,
9    current_index: Option<usize>,
10    previous_index: Option<usize>,
11}
12
13impl<T> ItemChange<T> {
14    /// `ItemChange(ListChangeReason, T, in Optional<T>, int, int)`.
15    pub fn new(reason: super::ListChangeReason, current: T, previous: Option<T>, current_index: Option<usize>, previous_index: Option<usize>) -> Self {
16        Self { reason, current, previous, current_index, previous_index }
17    }
18
19    /// The reason (`Reason`).
20    pub fn reason(&self) -> super::ListChangeReason {
21        self.reason
22    }
23
24    /// The item (`Current`).
25    pub fn current(&self) -> &T {
26        &self.current
27    }
28
29    /// The item that was replaced (`Previous`).
30    pub fn previous(&self) -> Option<&T> {
31        self.previous.as_ref()
32    }
33
34    /// The index of the item (`CurrentIndex`; `-1` upstream when none).
35    pub fn current_index(&self) -> Option<usize> {
36        self.current_index
37    }
38
39    /// The previous index of a moved item (`PreviousIndex`).
40    pub fn previous_index(&self) -> Option<usize> {
41        self.previous_index
42    }
43
44}