diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs index e74e04b4..87e6414a 100644 --- a/proxmox-api-macro/src/util.rs +++ b/proxmox-api-macro/src/util.rs @@ -584,6 +584,12 @@ pub enum Maybe { None, } +impl Default for Maybe { + fn default() -> Self { + Maybe::None + } +} + impl Maybe { pub fn as_ref(&self) -> Maybe<&T> { match self { @@ -600,6 +606,13 @@ impl Maybe { } } + pub fn ok(self) -> Option { + match self { + Maybe::Explicit(v) | Maybe::Derived(v) => Some(v), + Maybe::None => None, + } + } + pub fn ok_or_else(self, other: F) -> Result where F: FnOnce() -> E, @@ -613,6 +626,14 @@ impl Maybe { pub fn is_none(&self) -> bool { matches!(self, Maybe::None) } + + pub fn is_explicit(&self) -> bool { + matches!(self, Maybe::Explicit(_)) + } + + pub fn take(&mut self) -> Self { + std::mem::take(self) + } } impl Into> for Maybe {