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§
impl<T: Copy> Copy for Missing<T>
Source§impl<T: Eq> Eq for Missing<T>
impl<T: Eq> Eq for Missing<T>
Source§#[doc(hidden)]fn assert_fields_are_eq(&self)
#[doc(hidden)]fn assert_fields_are_eq(&self)
derive_eq_internals)1.0.0 (const: unstable) · Source§#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
implementation detail of #[derive(Eq)]
impl<T: PartialEq> StructuralPartialEq for Missing<T>
Source§impl<T> TryFromSexp for Missing<T>
impl<T> TryFromSexp for Missing<T>
Source§const NATIVE_BORROW: Option<NativeBorrow> = T::NATIVE_BORROW
const NATIVE_BORROW: Option<NativeBorrow> = T::NATIVE_BORROW
Source§const CHARACTER_ONLY: bool = T::CHARACTER_ONLY
const CHARACTER_ONLY: bool = T::CHARACTER_ONLY
NULL, is a character vector or a factor. Read moreSource§fn __mx_has_na(&self) -> bool
fn __mx_has_na(&self) -> bool
#[miniextendr(no_na)]
refuses after the conversion. Read moreSource§fn __mx_input_has_na(&self, input: SEXP) -> bool
fn __mx_input_has_na(&self, input: SEXP) -> bool
#[miniextendr(no_na)] refuses this converted argument, read
from input (the R value it converted from), when no R guard ran. Read moreSource§fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>
fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>
Source§unsafe fn try_from_sexp_unchecked(sexp: SEXP) -> Result<Self, Self::Error>
unsafe fn try_from_sexp_unchecked(sexp: SEXP) -> Result<Self, Self::Error>
Source§#[doc(hidden)]const __MX_EXPECTATION: Option<&'static str> = None
#[doc(hidden)]const __MX_EXPECTATION: Option<&'static str> = None
#[miniextendr] cannot tell from the type as written: the
<expected> of a failed conversion’s '<p>' must be <expected>: .... Read moreSource§#[doc(hidden)]unsafe fn __mx_try_from_rooted(root: Root<'_>) -> Result<Self, Self::Error>
#[doc(hidden)]unsafe fn __mx_try_from_rooted(root: Root<'_>) -> Result<Self, Self::Error>
Source§#[doc(hidden)]fn __mx_try_from_sexp_with_check(
sexp: SEXP,
check: &ElementCheck<'_>,
) -> Result<Self, SexpError>
#[doc(hidden)]fn __mx_try_from_sexp_with_check(
sexp: SEXP,
check: &ElementCheck<'_>,
) -> Result<Self, SexpError>
check, an element type’s
TryFromSexpElement::check_sexp,
on the R value that carries an element’s class (#1837). Read moreSource§#[doc(hidden)]unsafe fn __mx_try_from_sexp_unchecked_with_check(
sexp: SEXP,
check: &ElementCheck<'_>,
) -> Result<Self, SexpError>
#[doc(hidden)]unsafe fn __mx_try_from_sexp_unchecked_with_check(
sexp: SEXP,
check: &ElementCheck<'_>,
) -> Result<Self, SexpError>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ConsumingFallible for Twhere
T: Clone,
impl<T> Printable for T
Source§impl<T> RCopy for Twhere
T: Copy,
impl<T> RCopy for Twhere
T: Copy,
Source§impl<T> RDebug for Twhere
T: Debug,
impl<T> RDebug for Twhere
T: Debug,
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.