euv_ui/hook/toggle/impl.rs
1use super::*;
2
3/// Inherent implementation of [`Toggle`].
4impl Toggle {
5 /// Sets the value to `true`.
6 pub fn set_true(&self) {
7 self.get_value().set(true);
8 }
9
10 /// Sets the value to `false`.
11 pub fn set_false(&self) {
12 self.get_value().set(false);
13 }
14
15 /// Flips the value: `true` becomes `false`,
16 /// `false` becomes `true`.
17 pub fn toggle(&self) {
18 let current: bool = self.get_value().get();
19 self.get_value().set(!current);
20 }
21
22 /// Replaces the value with `next`.
23 ///
24 /// # Arguments
25 ///
26 /// - `bool` - A boolean (`bool`).
27 pub fn set(&self, next: bool) {
28 self.get_value().set(next);
29 }
30
31 /// Returns the current value as a snapshot.
32 ///
33 /// # Returns
34 ///
35 /// - `bool` - The current value (or a snapshot thereof).
36 pub fn get(&self) -> bool {
37 self.get_value().get()
38 }
39}
40
41/// Formatting / debug-printing for [`Toggle`].
42impl Display for Toggle {
43 /// Formats the [`Toggle`] via the supplied formatter.
44 ///
45 /// # Arguments
46 ///
47 /// - `&mut Formatter<'_>` - The formatter receiving the formatted output.
48 ///
49 /// # Returns
50 ///
51 /// - `FmtResult` - Result of the formatting operation.
52 fn fmt(&self, formatter: &mut Formatter<'_>) -> FmtResult {
53 write!(formatter, "Toggle({})", self.get_value().get())
54 }
55}
56
57/// Equality comparison for [`Toggle`].
58impl PartialEq for Toggle {
59 /// Returns `true` when `self` and `other` are equivalent by the [`PartialEq`] contract.
60 ///
61 /// # Arguments
62 ///
63 /// - `&Self` - The other value to compare against `self`.
64 ///
65 /// # Returns
66 ///
67 /// - `bool` - `true` when `self` and `other` are equivalent by the trait contract.
68 fn eq(&self, other: &Self) -> bool {
69 self.get_value().get() == other.get_value().get()
70 }
71}