Skip to main content

MatchArgError

Enum MatchArgError 

Source
pub enum MatchArgError {
    InvalidType {
        actual: SEXPTYPE,
        choices: &'static [&'static str],
        aliases: &'static [MatchArgAlias],
    },
    InvalidLength {
        actual: usize,
        choices: &'static [&'static str],
        aliases: &'static [MatchArgAlias],
    },
    IsNa {
        choices: &'static [&'static str],
        aliases: &'static [MatchArgAlias],
    },
    NoMatch {
        input: String,
        choices: &'static [&'static str],
        aliases: &'static [MatchArgAlias],
    },
}
Expand description

Error type for MatchArg conversion failures.

Every variant carries the type’s choices and aliases, so an error can say what the value must be ('mode' should be one of "fast", "slow" (or "quick" for "fast")) whichever way it was wrong.

Variants§

§

InvalidType

The SEXP was not a character or factor type.

Fields

§actual: SEXPTYPE

The SEXPTYPE that was given.

§choices: &'static [&'static str]

The valid choices.

§aliases: &'static [MatchArgAlias]

The type’s aliases (MatchArg::ALIASES).

§

InvalidLength

The input had length != 1.

Fields

§actual: usize

The length that was given.

§choices: &'static [&'static str]

The valid choices.

§aliases: &'static [MatchArgAlias]

The type’s aliases (MatchArg::ALIASES).

§

IsNa

The input was NA.

Fields

§choices: &'static [&'static str]

The valid choices.

§aliases: &'static [MatchArgAlias]

The type’s aliases (MatchArg::ALIASES).

§

NoMatch

No choice matched the input.

Fields

§input: String

The input string that didn’t match.

§choices: &'static [&'static str]

The valid choices.

§aliases: &'static [MatchArgAlias]

The type’s aliases (MatchArg::ALIASES).

Implementations§

Source§

impl MatchArgError

Source

fn invalid_type<T: MatchArg>(actual: SEXPTYPE) -> Self

InvalidType for the choices of T.

Source

fn invalid_length<T: MatchArg>(actual: usize) -> Self

InvalidLength for the choices of T.

Source

fn is_na<T: MatchArg>() -> Self

IsNa for the choices of T.

Source

fn no_match<T: MatchArg>(input: &str) -> Self

NoMatch of input for the choices of T.

Source

pub fn choices(&self) -> &'static [&'static str]

The choices the value should have been one of.

Source

pub fn aliases(&self) -> &'static [MatchArgAlias]

The aliases of the choices, listed and unlisted.

Source

pub fn expectation(&self) -> String

What the value must be, in R terms: one of "fast", "slow", with the listed aliases after the choices (one of "fast", "slow" (or "quick" for "fast")). An Either whose arms both refused a value names a match_arg arm with it ('x' must be one of "oral", "bolus", or a single double: got logical, #1594).

Source

pub fn arg_error(&self, param: &str) -> ArgError

The argument error the generated wrapper’s match_arg check (.miniextendr_match_arg) raises for this value of parameter param (its R name), word for word (#1741):

  • InvalidType: 'mode' must be NULL or a character vector
  • InvalidLength: 'mode' must be of length 1
  • IsNa, NoMatch: 'mode' should be one of "fast", "safe", then the listed aliases ('mode' should be one of "fast", "safe" (or "quick" for "fast"), #2148)

The choices and the aliases are quoted as R’s dQuote(choices, FALSE) quotes them, without escapes. match_arg_param returns it; ArgError::raise raises it as that condition. The generated conversion of a match_arg type, with or without #[miniextendr(match_arg)], raises its message too (#1767).

Source

pub(crate) fn arg_message(&self, param: &str, formal: &[&str]) -> String

The message of arg_error, with the choices listed in the order of formal, the choices of the parameter’s R formal: T::CHOICES, or those of a default = "..." parameter, which lists its default first (match_arg_param_with_default). The listed aliases follow in the order of T::CHOICES whatever the formal, as the wrappers writer renders them for the R check.

Source

pub(crate) fn r_reason(&self, expected_known: bool) -> String

The reason of this error in R terms, after <expected>: when an Either names this arm in an argument error (#1591): got "zzz", got numeric, got length 2, NA is not allowed. With expected_known = false (nothing before the reason names the choices) it is the Display text, which says what was expected.

Trait Implementations§

Source§

impl Clone for MatchArgError

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 ConversionArgMessageBuiltin for MatchArgError

Source§

impl ConversionErrBuiltin for MatchArgError

Source§

fn __mx_conversion_parts(&self, expected_known: bool) -> ErrParts

Source§

impl ConversionExpectBuiltin for MatchArgError

Source§

impl Debug for MatchArgError

Source§

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

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

impl Display for MatchArgError

The text is complete on its own, for a conversion outside an argument: expected one of "fast", "slow", got "zzz", expected a string or factor, got numeric.

Source§

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

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

impl Error for MatchArgError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
Source§

#[doc(hidden)]
fn type_id(&self, _: Internal) -> TypeId
where Self: 'static,

🔬This is a nightly-only experimental API. (error_type_id)
Gets the TypeId of self.
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<MatchArgError> for SexpError

Kept whole, so a TryFromSexp whose error is SexpError (the one #[derive(MatchArg)] emits) still reports the choices.

Source§

fn from(e: MatchArgError) -> Self

Converts to this type from the input type.

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> ConsumingFallible for T
where T: Clone,

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 r_clone(&self) -> T

Create a deep copy of this value.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RClone_r_clone_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RClone + IntoR,

Method shim for RClone::r_clone. 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§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDebug_debug_str_pretty_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDebug,

Method shim for RDebug::debug_str_pretty. Read more
Source§

impl<T> RDisplay for T
where T: Display,

Source§

fn as_r_string(&self) -> String

Convert to a user-friendly string.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RDisplay_as_r_string_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RDisplay,

Method shim for RDisplay::as_r_string. Read more
Source§

impl<T> RError for T
where T: Error,

Source§

fn error_message(&self) -> String

Get the error message (Display representation).
Source§

fn error_chain(&self) -> Vec<String>

Get all error messages in the chain, from outermost to innermost.
Source§

fn error_chain_length(&self) -> i32

Get the number of errors in the chain.
Source§

#[doc(hidden)]
unsafe extern "C" fn __RError_error_message_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_message. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_chain. Read more
Source§

#[doc(hidden)]
unsafe extern "C" fn __RError_error_chain_length_shim( data: *mut c_void, argc: i32, argv: *const SEXP, ) -> SEXP
where Self: Sized + RError,

Method shim for RError::error_chain_length. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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: 56 bytes

Size for each variant:

  • InvalidType: 48 bytes
  • InvalidLength: 48 bytes
  • IsNa: 40 bytes
  • NoMatch: 56 bytes