Skip to main content

Module nullable

Module nullable 

Source
Expand description

The NULL-on-None return type (Nullable<T>). Nullable<T>: an optional return whose None is NULL in R.

An Option<T> return converts through Option<T>’s own IntoR: None is NULL for a vector, list or class, but NA for a scalar (Option<i32> gives NA_integer_), because R stores a missing scalar as NA. Where None means that there is no value at all, whatever T is, return Nullable<T>: Some(v) converts as v does, and None is NULL. [RIterator] uses it for the end of iteration, which an NA item would be indistinguishable from.

ⓘ
use miniextendr_api::{miniextendr, Nullable};

#[miniextendr]
pub fn first_even(xs: Vec<i32>) -> Nullable<i32> {
    Nullable(xs.into_iter().find(|x| x % 2 == 0))
}
// R: first_even(c(1L, 4L)) → 4L
//    first_even(c(1L, 3L)) → NULL  (an `Option<i32>` return gives NA_integer_)

Nullable<T> is a return type only; an optional argument is Option<T>, which already reads NULL as None.

Structs§

Nullable
An optional return value that R receives as NULL when None, whatever T is. See the module docs.