add helper methods on the settings

This commit is contained in:
Irevoire 2021-10-13 13:05:07 +02:00
parent 6e3b869e6a
commit a3e7c468cd
No known key found for this signature in database
GPG Key ID: 7A6A970C96104F1B

View File

@ -28,6 +28,21 @@ impl<T> Default for Setting<T> {
}
impl<T> Setting<T> {
pub fn set(self) -> Option<T> {
match self {
Self::Set(value) => Some(value),
_ => None,
}
}
pub const fn as_ref(&self) -> Setting<&T> {
match *self {
Self::Set(ref value) => Setting::Set(value),
Self::Reset => Setting::Reset,
Self::NotSet => Setting::NotSet,
}
}
pub const fn is_not_set(&self) -> bool {
matches!(self, Self::NotSet)
}