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: boolno_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
impl ExplicitChecks
Sourcepub fn merge(&mut self, other: ExplicitChecks) -> Result<(), String>
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.
Sourcepub fn class_conflict(&self, param: &str) -> Option<String>
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.
Sourcefn class_assertions(&self, param: &str, ty: &Type) -> Vec<RAssertion>
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).
Sourcefn value_assertions(
&self,
param: &str,
ty: &Type,
choice: bool,
) -> Vec<RAssertion>
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).
Sourcefn type_check_message(&self) -> Option<&String>
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
impl Clone for ExplicitChecks
Source§impl Debug for ExplicitChecks
impl Debug for ExplicitChecks
Source§impl Default for ExplicitChecks
impl Default for ExplicitChecks
Source§impl Eq for ExplicitChecks
impl Eq for ExplicitChecks
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)]
Source§impl PartialEq for ExplicitChecks
impl PartialEq for ExplicitChecks
impl StructuralPartialEq for ExplicitChecks
Auto Trait Implementations§
impl Freeze for ExplicitChecks
impl RefUnwindSafe for ExplicitChecks
impl Send for ExplicitChecks
impl Sync for ExplicitChecks
impl Unpin for ExplicitChecks
impl UnsafeUnpin for ExplicitChecks
impl UnwindSafe for ExplicitChecks
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,
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: 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