1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! `BindingOptions` (`Binding/BindingOptions.cs`).
/// The options of the binding of change sets to an observable collection (`BindingOptions`).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct BindingOptions {
/// The number of changes above which the collection is loaded again and a reset is raised
/// (`ResetThreshold`).
pub reset_threshold: usize,
/// Whether an update replaces the item in place, rather than removing and adding it
/// (`UseReplaceForUpdates`).
pub use_replace_for_updates: bool,
/// Whether the first change set loads the collection with a reset (`ResetOnFirstTimeLoad`).
pub reset_on_first_time_load: bool,
}
impl BindingOptions {
/// `DefaultResetThreshold`.
pub const DEFAULT_RESET_THRESHOLD: usize = 25;
/// `DefaultUseReplaceForUpdates`.
pub const DEFAULT_USE_REPLACE_FOR_UPDATES: bool = true;
/// `DefaultResetOnFirstTimeLoad`.
pub const DEFAULT_RESET_ON_FIRST_TIME_LOAD: bool = true;
/// The options with the threshold and upstream's defaults for the others
/// (`BindingOptions(int ResetThreshold)`).
pub const fn new(reset_threshold: usize) -> Self {
Self { reset_threshold, use_replace_for_updates: Self::DEFAULT_USE_REPLACE_FOR_UPDATES, reset_on_first_time_load: Self::DEFAULT_RESET_ON_FIRST_TIME_LOAD }
}
/// Every part (`BindingOptions(int, bool, bool)`).
pub const fn with_all(reset_threshold: usize, use_replace_for_updates: bool, reset_on_first_time_load: bool) -> Self {
Self { reset_threshold, use_replace_for_updates, reset_on_first_time_load }
}
/// The options that never reset the collection (`NeverFireReset(bool useReplaceForUpdates =
/// true)`).
pub const fn never_fire_reset() -> Self {
Self::never_fire_reset_with(Self::DEFAULT_RESET_ON_FIRST_TIME_LOAD)
}
/// [`never_fire_reset`](Self::never_fire_reset) with the choice of replacements
/// (`NeverFireReset(bool)`).
pub const fn never_fire_reset_with(use_replace_for_updates: bool) -> Self {
Self { reset_threshold: usize::MAX, use_replace_for_updates, reset_on_first_time_load: false }
}
/// A copy with another threshold (`with { ResetThreshold = .. }`).
pub const fn with_reset_threshold(self, reset_threshold: usize) -> Self {
Self { reset_threshold, ..self }
}
/// A copy with another choice of replacements (`with { UseReplaceForUpdates = .. }`).
pub const fn with_use_replace_for_updates(self, use_replace_for_updates: bool) -> Self {
Self { use_replace_for_updates, ..self }
}
/// A copy with another choice of the first load (`with { ResetOnFirstTimeLoad = .. }`).
pub const fn with_reset_on_first_time_load(self, reset_on_first_time_load: bool) -> Self {
Self { reset_on_first_time_load, ..self }
}
}
impl Default for BindingOptions {
/// `new BindingOptions(DefaultResetThreshold)`.
fn default() -> Self {
Self::new(Self::DEFAULT_RESET_THRESHOLD)
}
}