Expand description
#[derive(TryFromSexp)] / #[derive(IntoR)] — forward R↔Rust conversions
from a single-field newtype to its inner type. #[derive(IsNA)] uses
the same parser to forward native missing-value detection.
For a newtype struct UserId(Uuid) (or struct UserId { inner: Uuid }):
#[derive(TryFromSexp)]generates the R → Rust direction: a scalarTryFromSexpimpl that forwards to the inner type, plus aminiextendr_api::TryFromSexpElementmarker impl. The marker lets the container blankets inminiextendr_api::newtypelight upVec<UserId>/Option<UserId>/Vec<Option<UserId>>— see issues #844 and #1766.#[derive(IntoR)]generates the Rust → R direction: a scalarIntoRimpl that forwards to the inner type, plusminiextendr_api::IntoRNewtype(forOption/Vec<Option>) and a concreteminiextendr_api::IntoRVecElementimpl (forVec).
Direction is chosen by which derive you list. Some inner types are
convertible in only one direction (a compiled regex::Regex reads from R
but cannot be written back): derive only TryFromSexp for those.
#[derive(TryFromSexp)] // R -> Rust only
struct Pattern(regex::Regex);
#[derive(TryFromSexp, IntoR)] // round-trip
struct UserId(uuid::Uuid);#[derive(TryFromSexp)] takes one attribute, on the struct:
#[try_from_sexp(validate = path::to::check)], with check a
fn(SEXP) -> Result<(), E> and E: Into<SexpError> (an RError or any
RConditionData type for a classed refusal). It becomes
TryFromSexpElement::check_sexp, which the
scalar impl and every container run on the R value before the inner type
reads it (#1815). The scalar impl’s error is then SexpError, so the inner
type’s error must convert into it.
Do not derive both IntoR and MatchArg on the same type: both would feed
the single IntoR for Vec<T> blanket slot and collide (E0119).
Structs§
- Newtype 🔒
- The single field of a newtype: its inner type plus how to wrap/unwrap it.
- TryFrom
Sexp 🔒Options - The
#[try_from_sexp(...)]options of#[derive(TryFromSexp)].
Functions§
- derive_
into_ r #[derive(IntoR)]: scalar forwardingIntoR+IntoRNewtypemarker (forOption/Vec<Option>blankets) + concreteIntoRVecElement(forVec).- derive_
is_ na #[derive(IsNA)]: delegate native missing-value detection to the field.- derive_
try_ from_ sexp #[derive(TryFromSexp)]: scalar forwardingTryFromSexp+TryFromSexpElementmarker.- expectation_
const 🔒 - The newtype’s
TryFromSexp::__MX_EXPECTATION: what an argument of the inner type must be, in R terms, so a newtype parameter orEitherarm reads as its inner type does (struct Dose(AsNumeric):a single number). The macro’s own wording when it knows the inner type (crate::r_preconditions::conversion_expectation), else the inner type’s constant, which a newtype of a newtype carries through. - parse_
newtype 🔒 - parse_
try_ 🔒from_ sexp_ options - Read the struct’s
#[try_from_sexp(...)]attributes. The only key isvalidate = path; any other key, a repeatedvalidate, or the attribute on the field is a spanned error. - where_
with 🔒 - Build a
whereclause that merges the struct’s existing predicates with extra predicates (theInner: Traitbounds the forwarding impl requires).