setting/methods/
mod.rs

1use crate::Setting;
2
3impl<T> Setting<T>
4where
5    T: Default,
6{
7    /// Set a value to this field.
8    pub fn set(&mut self, value: T) {
9        *self = Self::Normal(value);
10    }
11    /// Reset value of this field to default.
12    pub fn reset(&mut self) {
13        *self = Self::Initial;
14    }
15    /// Unset the current value
16    pub fn unset(&mut self) {
17        *self = Self::Unset;
18    }
19    /// Get value of this field
20    pub fn unwrap(self) -> T {
21        match self {
22            Self::Initial | Self::Unset => Default::default(),
23            Self::Normal(t) => t,
24        }
25    }
26    /// Check if this field has not been set
27    pub fn is_default(&self) -> bool {
28        matches!(self, Self::Initial)
29    }
30    /// Check if this field has been set to none
31    pub fn is_none(&self) -> bool {
32        matches!(self, Self::Unset)
33    }
34    /// Check if this field has been set to some value
35    pub fn is_some(&self) -> bool {
36        matches!(self, Self::Normal(_))
37    }
38}