pub enum Missing<T> {
Present(T),
Absent,
}Expand description
Wrapper type that detects if an R argument was not passed (missing).
This corresponds to R’s missing() function. When a function parameter
has type Missing<T>, it will be Missing::Absent if the caller didn’t
provide that argument, or Missing::Present(value) if they did.
§Example
ⓘ
use miniextendr_api::{miniextendr, Missing};
#[miniextendr]
fn maybe_square(x: Missing<f64>) -> f64 {
match x {
Missing::Present(val) => val * val,
Missing::Absent => 0.0,
}
}In R:
maybe_square(5) # 25
maybe_square() # 0Variants§
Implementations§
Source§impl<T> Missing<T>
impl<T> Missing<T>
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Returns true if the argument was provided.
Sourcepub fn is_missing(&self) -> bool
pub fn is_missing(&self) -> bool
Returns true if the argument was not provided.
Named to match R’s missing() function.
Sourcepub fn into_option(self) -> Option<T>
pub fn into_option(self) -> Option<T>
Convert to Option<T>, returning None if missing.
Sourcepub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
Returns the contained value or computes it from a closure.
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Missing<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Missing<U>
Maps Missing<T> to Missing<U> by applying a function.
Trait Implementations§
Source§impl<T> TryFromSexp for Missing<T>
impl<T> TryFromSexp for Missing<T>
impl<T: Copy> Copy for Missing<T>
impl<T: Eq> Eq for Missing<T>
impl<T> StructuralPartialEq for Missing<T>
Auto Trait Implementations§
impl<T> Freeze for Missing<T>where
T: Freeze,
impl<T> RefUnwindSafe for Missing<T>where
T: RefUnwindSafe,
impl<T> Send for Missing<T>where
T: Send,
impl<T> Sync for Missing<T>where
T: Sync,
impl<T> Unpin for Missing<T>where
T: Unpin,
impl<T> UnsafeUnpin for Missing<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for Missing<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more