Skip to main content

ExplicitChecks

Struct ExplicitChecks 

Source
pub struct ExplicitChecks {
    pub inherits: Option<Vec<String>>,
    pub inherits_message: Option<String>,
    pub inherits_hints: Vec<InheritsHint>,
    pub not_inherits: Option<Vec<String>>,
    pub not_inherits_message: Option<String>,
    pub no_na: bool,
    pub no_na_message: Option<String>,
}
Expand description

R-side checks the author asked for by name on one parameter, rather than ones derived from its Rust type.

Spelled #[miniextendr(inherits = "cls", not_inherits = "bad", no_na)] on a standalone fn parameter, or inherits(x = "cls") / not_inherits(x = "bad") / no_na(x) on an impl or trait method. They are the same kind of guards as the type checks, raising the same argument error. The class checks run before the parameter’s type checks, so a value of the wrong class gets the class message whatever its type: inherits first, then not_inherits (#1815). That order matters for the classes a not_inherits typically refuses: is.numeric() is FALSE for a difftime, Date or POSIXt, so after an AsNumeric type check the refusal would never be reached. An inherits message also replaces the messages of the parameter’s type checks; a not_inherits message does not, since a value that passes it is of none of the refused classes and is judged by its type. The NA check runs after the type checks, with its own message. All survive no_preconditions: the Rust conversion does not repeat them, so dropping them would change what the function accepts.

no_na also has a Rust half. A type can read more inputs as missing than anyNA() sees (the reading markers AsNumeric* / AsCharacter* read the text "NA", blank strings, a factor NA level as NA), so the C wrapper checks the converted value too (TryFromSexp::__mx_has_na, see RustConversionBuilder::with_no_na) and raises the same condition with the same message (no_na_message). An Either parameter has only the Rust half: the arm the value converted to checks the input (no_na_checked_after_conversion).

Each check can carry the author’s own condition message (inherits(class = "cls", message = "..."), not_inherits(class = "bad", message = "..."), no_na(message = "..."); method level inherits(x(class = "cls", message = "...")), not_inherits(x(class = "bad", message = "...")), no_na(x(message = "..."))), used verbatim in place of the generated 'x' must inherit from 'cls'. The condition is otherwise the same.

An inherits check can also give a value that fails it a message chosen by the value’s class (#1824): inherits(class = "cls", when(class = "data.frame", message = "...")), method level inherits(x(class = "cls", when(class = "data.frame", message = "..."))) (InheritsHint).

Fields§

§inherits: Option<Vec<String>>

inherits = "cls" / inherits("a", "b"): the argument must inherit from at least one of these classes (inherits(x, c(...))).

§inherits_message: Option<String>

message = "..." in inherits(...): the message of a failed class check, for all of its classes, and of that parameter’s R type checks. Only set together with inherits.

§inherits_hints: Vec<InheritsHint>

when(class = "...", message = "...") in inherits(...): the messages a value that fails the inherits check gets for its class, in the order written. Only set together with inherits.

§not_inherits: Option<Vec<String>>

not_inherits = "cls" / not_inherits("a", "b"): the argument must inherit from none of these classes (!inherits(x, c(...)), #1815).

§not_inherits_message: Option<String>

message = "..." in not_inherits(...): the message of a failed not_inherits check, for all of its classes. Unlike the inherits message it leaves the type checks’ messages alone. Only set together with not_inherits.

§no_na: bool

no_na: the argument must not contain NA (!anyNA(x), so NaN is refused too, as is.na() does), nor a value its type reads as NA (checked in Rust after the conversion). For an Either, both checks run in Rust, by the arm the value converted to.

§no_na_message: Option<String>

no_na(message = "..."): the message of a failed NA check. Only set together with no_na.

Implementations§

Source§

impl ExplicitChecks

Source

pub fn is_empty(&self) -> bool

Whether any check is requested.

Source

pub fn merge(&mut self, other: ExplicitChecks) -> Result<(), String>

Merge other into self (a parameter may carry several attributes). The inherits hints of other follow those of self, so the hints keep the order they are written in.

Fails when both give a message for the same check; the error names the check.

Source

pub fn class_conflict(&self, param: &str) -> Option<String>

The error for a parameter whose checks contradict each other: a class both in inherits and in not_inherits, which no argument could satisfy through that class, or an inherits class in a when(...) hint, whose message could never be shown (a value of that class passes inherits). None when they agree.

A hint class may also be a not_inherits class: a value of that class alone gets the hint, and one that also inherits from a required class passes the hint and inherits and is refused by not_inherits.

Run once every attribute of the parameter is merged: the inherits = "cls" spelling adds its class without a merge, and a hint can name a class that another attribute requires.

Source

fn class_assertions(&self, param: &str, ty: &Type) -> Vec<RAssertion>

The class checks (inherits, then not_inherits) for parameter param of type ty, which run before the parameter’s type checks. Empty without either.

The inherits hints come first, one check each in the order written, so a refused value gets the first hint naming one of its classes: inherits(p, <required>) || !inherits(p, <hint classes>), failing with the hint’s message. A value that passes inherits passes every hint, so a hint changes the message of a refusal, never what is accepted.

An Option<T> / Missing<T> parameter passes NULL / an omitted argument (see guarded).

Source

fn value_assertions( &self, param: &str, ty: &Type, choice: bool, ) -> Vec<RAssertion>

The NA check (no_na) for parameter param of type ty, which runs after the parameter’s type checks, with its own message. Empty without no_na, and for an Either parameter that is not a choice parameter (choice: match_arg / choices), whose NA check runs in Rust after the conversion (no_na_checked_after_conversion).

An Option<T> / Missing<T> parameter passes NULL / an omitted argument (see guarded).

Source

fn type_check_message(&self) -> Option<&String>

The message of the parameter’s R type checks: the inherits message, when there is one. Without it the type checks keep their generated messages. A not_inherits message is not one: a value that passed not_inherits is of none of the refused classes, so its type check keeps its own wording.

Trait Implementations§

Source§

impl Clone for ExplicitChecks

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ExplicitChecks

Source§

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

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

impl Default for ExplicitChecks

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for ExplicitChecks

Source§

#[doc(hidden)]
fn assert_fields_are_eq(&self)

🔬This is a nightly-only experimental API. (derive_eq_internals)
1.0.0 (const: unstable) · Source§

#[doc(hidden)]
fn assert_receiver_is_total_eq(&self)

👎Deprecated since 1.95.0:

implementation detail of #[derive(Eq)]

Source§

impl PartialEq for ExplicitChecks

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ExplicitChecks

Auto Trait Implementations§

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<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> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)]
const SIZE: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const ALIGNMENT: Alignment = _

🔬This is a nightly-only experimental API. (ptr_alignment_type)
Source§

#[doc(hidden)]
const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)]
const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)]
const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 152 bytes