Skip to main content

Missing

Enum Missing 

Source
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()   # 0

Variants§

§

Present(T)

The argument was provided.

§

Absent

The argument was not provided (missing in R).

Implementations§

Source§

impl<T> Missing<T>

Source

pub fn is_present(&self) -> bool

Returns true if the argument was provided.

Source

pub fn is_missing(&self) -> bool

Returns true if the argument was not provided.

Named to match R’s missing() function.

Source

pub fn into_option(self) -> Option<T>

Convert to Option<T>, returning None if missing.

Source

pub fn as_ref(&self) -> Missing<&T>

Get a reference to the value if present.

Source

pub fn as_mut(&mut self) -> Missing<&mut T>

Get a mutable reference to the value if present.

Source

pub fn unwrap_or(self, default: T) -> T

Returns the contained value or a default.

Source

pub fn unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T

Returns the contained value or computes it from a closure.

Source

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Missing<U>

Maps Missing<T> to Missing<U> by applying a function.

Source

pub fn unwrap(self) -> T

Returns the contained value, panicking if absent.

§Panics

Panics if the value is Absent.

Source

pub fn expect(self, msg: &str) -> T

Returns the contained value, panicking with a custom message if absent.

§Panics

Panics with the provided message if the value is Absent.

Source§

impl<T: Default> Missing<T>

Source

pub fn unwrap_or_default(self) -> T

Returns the contained value or the default for that type.

Trait Implementations§

Source§

impl<T: Clone> Clone for Missing<T>

Source§

fn clone(&self) -> Missing<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Missing<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Missing<T>

Source§

fn default() -> Self

The default is Absent.

Source§

impl<T> From<Missing<T>> for Option<T>

Source§

fn from(missing: Missing<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Option<T>> for Missing<T>

Source§

fn from(opt: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for Missing<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: PartialEq> PartialEq for Missing<T>

Source§

fn eq(&self, other: &Missing<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> TryFromSexp for Missing<T>

Source§

type Error = SexpError

The error type returned when conversion fails.
Source§

fn try_from_sexp(sexp: SEXP) -> Result<Self, Self::Error>

Attempt to convert an R SEXP to this Rust type. Read more
Source§

unsafe fn try_from_sexp_unchecked(sexp: SEXP) -> Result<Self, Self::Error>

Convert from SEXP without thread safety checks. Read more
Source§

impl<T: Copy> Copy for Missing<T>

Source§

impl<T: Eq> Eq for Missing<T>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> RClone for T
where T: Clone,

Source§

fn clone(&self) -> T

Create a deep copy of this value.
Source§

impl<T> RCopy for T
where T: Copy,

Source§

fn copy(&self) -> T

Create a bitwise copy of this value. Read more
Source§

fn is_copy(&self) -> bool

Check if this type implements Copy. Read more
Source§

impl<T> RDebug for T
where T: Debug,

Source§

fn debug_str(&self) -> String

Get a compact debug string representation.
Source§

fn debug_str_pretty(&self) -> String

Get a pretty-printed debug string with indentation.
Source§

impl<T> RDefault for T
where T: Default,

Source§

fn default() -> T

Create a new instance with default values.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.