Skip to main content

ParamAttrs

Struct ParamAttrs 

Source
pub(crate) struct ParamAttrs {
    pub coerce: bool,
    pub match_arg: bool,
    pub several_ok: bool,
    pub choices: Option<Vec<String>>,
    pub default: Option<String>,
    pub optional: bool,
    pub omittable: bool,
    pub no_default: bool,
    pub either_noun: Option<String>,
    pub checks: ExplicitChecks,
    pub preconditions: Option<bool>,
    pub formal: Option<LitStr>,
}
Expand description

Collapsed per-parameter attribute state for a single function parameter.

Built during parsing from #[miniextendr(coerce | match_arg | several_ok | no_default | default = "…" | choices("…"))] on the argument. Accessors on MiniextendrFunctionParsed query this struct rather than looking through multiple side-tables.

Fields§

§coerce: bool§match_arg: bool§several_ok: bool§choices: Option<Vec<String>>§default: Option<String>§optional: bool

Option<..> layer of a match_arg / choices parameter (#1473): NULL means no choice, so the prelude skips the check for it and Rust sees None. Unless Self::omittable is set too, the R formal is NULL instead of the choice vector. Set from the parameter type by classify_choice_param; together with several_ok only under an Either layer (Option<Either<Vec<T>, R>>), since a plain several_ok list already reads NULL as every choice.

§omittable: bool

Missing<..> layer of a match_arg / choices parameter (#1551): the R formal keeps the choice vector, the prelude skips the check for an omitted argument, and Rust sees Missing::Absent; a single choice reads its formal passed whole the same way (Self::absent_formal, #2152). Set by classify_choice_param.

§no_default: bool

no_default on a match_arg / choices parameter (#1828): the R formal is the bare name instead of the choice vector (or NULL), so an omitted argument is Missing::Absent under Missing<..> and R’s missing-argument error otherwise. The prelude and the choice list do not change. Set from the parameter’s no_default or the method’s no_default(p).

§either_noun: Option<String>

Either<.., R> layer of a match_arg / choices parameter, over a scalar choice (Either<T, R>) or a several_ok list (Either<Vec<T>, R> / Either<Box<[T]>, R>): the R-facing name of the R arm ("a data frame", see crate::type_inspect::r_value_noun) for the @param line. The prelude checks only character or factor input; anything else, NULL included, reaches Rust unchanged and decodes as R. Set by classify_choice_param.

§checks: ExplicitChecks

R-side checks named by the author: inherits / not_inherits / no_na.

§preconditions: Option<bool>

This parameter’s own decision on its type-derived R-side checks (#1566), rank 1 of crate::r_preconditions::resolve_type_checks: a Checked<T> / Unchecked<T> marker, the per-parameter preconditions / no_preconditions, or a method’s preconditions(x) / no_preconditions(x). Some(true) keeps them; None defers to the function, impl and crate defaults.

§formal: Option<LitStr>

The declared R formal (#1842): a standalone function’s formal = "conf.int" or a method’s formal(conf_int = "conf.int"), with the literal that declared it. Read through crate::r_wrapper_builder::Formals, never directly.

Implementations§

Source§

impl ParamAttrs

Source

pub(crate) fn leaves_argument_unforced(&self, default_ok: bool) -> bool

Whether this parameter’s options leave its argument unforced, as a Quoted / Quosure parameter needs (#1835): none but formal, which only names it (#1842), and default when default_ok (a Missing<Quoted> / Missing<Quosure> parameter, whose default only writes the formal).

Source

pub(crate) fn is_choice(&self) -> bool

Whether this is a match_arg / choices parameter.

Source

pub(crate) fn choice_formal(&self, choices: &str) -> Option<String>

The R formal default of a choice parameter, given its choice list (c("a", "b") or the write-time placeholder): NULL for the Option<T> form (#1473), the choice list otherwise, including Missing<Option<T>>, whose omission is reported by Missing (#1551). None under no_default (#1828): the formal is the bare name. The prelude spells the choice list out either way, so a match_arg placeholder then lives in the prelude only.

Source

pub(crate) fn absent_formal<'c>(&self, choices: &'c str) -> Option<&'c str>

The value that reads as omitted (#2152): choices, which is then the formal (Self::choice_formal), for a single-choice Missing<..> parameter. Its wrapper skips the check for a value identical() to it and forwards the missing-argument sentinel in its place, so passing the default shown in the usage line reaches Rust as Missing::Absent, like leaving it out. None for every other parameter: a several_ok list reads the whole vector as every choice, a parameter without Missing reads it as the first choice, and a no_default one has no vector in its formal.

Source

pub(crate) fn choice_list(&self, c_ident: &str, key: &str) -> Option<String>

The R expression for this parameter’s choice list, as its formal and its prelude check spell it: the write-time placeholder of a match_arg parameter (keyed by the C wrapper c_ident and the parameter’s crate::match_arg_keys::param_key key), c("a", "b") for choices(...), None for any other parameter.

Source

pub(crate) fn choice_doc_suffix(&self) -> String

The text after the quoted choice list in the auto-generated @param line (One of "a", "b"<suffix>.): the other accepted values, then an omission note. , or NULL for no choice for Option<T>, , or a data frame for Either<T, DataFrame>, , a data frame, or NULL for no choice for both, , or NULL; omitting the argument or passing the whole list means no choice for Missing<Option<T>>, ; omitting the argument or passing the whole list means no choice for Missing<T> (#2152; see Self::absent_formal), and nothing for a plain choice. A Missing<Vec<T>> several_ok list, whose whole vector selects every choice, says only ; omitting the argument means no choice. Under no_default (#1828) the omission note goes (the author documents what omission means) and the rest stays.

Source

pub(crate) fn literal_choices_doc(&self) -> Option<String>

The auto-generated @param text of a choices(...) parameter: One of "a", "b"<suffix>. (One or more of for several_ok), with Self::choice_doc_suffix. None without a literal choice list; a match_arg parameter’s text is only known at write time (its placeholder, #210).

Source

pub(crate) fn layered_leaf(&self) -> Option<ChoiceLeaf>

How the C wrapper decodes this parameter when a plain TryFromSexp cannot: a match_arg parameter with a Missing / Option / Either layer (MatchArgSeveral for a several_ok list, Either<Vec<T>, R> included), or a choices parameter with an Either layer (its string type or several_ok string list on the left). None for every other parameter (a choices string type converts through TryFromSexp with its Missing / Option layers; a plain several_ok container has its own path).

Trait Implementations§

Source§

impl Clone for ParamAttrs

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 ParamAttrs

Source§

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

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

impl Default for ParamAttrs

Source§

fn default() -> Self

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

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: 240 bytes