Expand description
Strict conversion helpers for #[miniextendr(strict)].
These functions panic instead of silently widening when a value cannot be
exactly represented as an R integer (INTSXP). This provides an opt-in
alternative to the default IntoR behavior which silently falls back to
REALSXP (f64) for out-of-range values.
§Motivation
R has no native 64-bit integer type. The default i64::into_sexp() picks
INTSXP when the value fits and REALSXP otherwise — silently losing
precision for values outside [-2^53, 2^53]. With #[miniextendr(strict)],
the macro generates calls to these helpers instead, which panic (→ R error)
if the value doesn’t fit in i32.
§Paired with
This is the strict outbound path. Its lax counterpart is the bare
IntoR impls for i64/u64/isize/usize (see crate::into_r).
Failure mode of staying on the lax path when you cared about exact
representation: a counter / ID just above i32::MAX lands in R as
REALSXP, and anything above 2^53 starts colliding silently.
There is no TryFromSexpStrict trait — inbound is already
strict-by-default because crate::from_r::TryFromSexp returns
Result<T, SexpError>. The looser inbound path is
crate::coerce::Coerce / crate::coerce::TryCoerce.
For storage-directed conversions (force Vec<i64> into INTSXP and error
if any element doesn’t fit) see crate::into_r_as::IntoRAs — it’s a
third path with value-based runtime checks.
Macros§
Constants§
- NA_
NOT_ 🔒ALLOWED - The element reason for an R
NAin a strict input that cannot hold one.
Traits§
- StrictR
Int 👻 - A lossy integer type for the strict outbound path: its R integer, if any, and the reason it has none.
Functions§
- batch_
elements 🔒 - Convert every element of
slice, batching every failure (its reason and 1-based position) into oneSexpError::InvalidValueinstead of stopping at the first. - checked_
elems_ 🔒into_ sexp - The
Vec<T>/Vec<Option<T>>strict conversion:NoneisNA_integer_. - checked_
into_ sexp_ i64 - Convert
i64to R integer, panicking if outside i32 range. - checked_
into_ sexp_ isize - Convert
isizeto R integer, panicking if outside i32 range. - checked_
into_ sexp_ u64 - Convert
u64to R integer, panicking if > i32::MAX. - checked_
into_ sexp_ usize - Convert
usizeto R integer, panicking if > i32::MAX. - checked_
option_ i64_ into_ sexp - Convert
Option<i64>to R integer in strict mode. Panics ifSome(x)is outside i32 range.NonebecomesNA_integer_. - checked_
option_ isize_ into_ sexp - Convert
Option<isize>to R integer in strict mode. - checked_
option_ u64_ into_ sexp - Convert
Option<u64>to R integer in strict mode. Panics ifSome(x)exceeds i32::MAX.NonebecomesNA_integer_. - checked_
option_ usize_ into_ sexp - Convert
Option<usize>to R integer in strict mode. - checked_
rows_ 👻into_ sexp - The list-of-vectors strict conversion (
Vec<Vec<T>>,Vec<Option<Vec<T>>>): validate every element of every row, then build the list of integer vectors (Nonerows becomeNULL). - checked_
scalar_ 🔒into_ sexp - The scalar strict conversion: the R integer, or the panic.
- checked_
slice_ 👻into_ sexp - Strict conversion shared by borrowed slices, boxed slices and arrays. Generated wrappers supply the written return type for the diagnostic.
- checked_
try_ from_ sexp_ i64 - Convert R SEXP to
i64in strict mode. - checked_
try_ from_ sexp_ isize - Convert R SEXP to
isizein strict mode. - checked_
try_ 🔒from_ sexp_ numeric_ scalar - Generic strict scalar conversion: only INTSXP and REALSXP allowed, of
length 1 and not
NA. - checked_
try_ from_ sexp_ u64 - Convert R SEXP to
u64in strict mode. - checked_
try_ from_ sexp_ usize - Convert R SEXP to
usizein strict mode. - checked_
vec_ i64_ into_ sexp - Convert
Vec<i64>to R integer vector, panicking if any element is outside i32 range. - checked_
vec_ isize_ into_ sexp - Convert
Vec<isize>to R integer vector, panicking if any element is outside i32 range. - checked_
vec_ option_ i64_ into_ sexp - Convert
Vec<Option<i64>>to R integer vector in strict mode. - checked_
vec_ option_ isize_ into_ sexp - Convert
Vec<Option<isize>>to R integer vector in strict mode. - checked_
vec_ option_ try_ from_ sexp_ i64 - Convert R SEXP to
Vec<Option<i64>>in strict mode. - checked_
vec_ option_ try_ from_ sexp_ isize - Convert R SEXP to
Vec<Option<isize>>in strict mode. - checked_
vec_ 🔒option_ try_ from_ sexp_ numeric - Generic strict
Vec<Option<T>>conversion: only INTSXP and REALSXP allowed. - checked_
vec_ option_ try_ from_ sexp_ u64 - Convert R SEXP to
Vec<Option<u64>>in strict mode. - checked_
vec_ option_ try_ from_ sexp_ usize - Convert R SEXP to
Vec<Option<usize>>in strict mode. - checked_
vec_ option_ u64_ into_ sexp - Convert
Vec<Option<u64>>to R integer vector in strict mode. - checked_
vec_ option_ usize_ into_ sexp - Convert
Vec<Option<usize>>to R integer vector in strict mode. - checked_
vec_ option_ vec_ i64_ into_ sexp - Convert
Vec<Option<Vec<i64>>>to an R list of integer vectors (None→NULL), panicking if any element of any row is outside i32 range. - checked_
vec_ option_ vec_ isize_ into_ sexp - Convert
Vec<Option<Vec<isize>>>to an R list of integer vectors (None→NULL), panicking if any element of any row is outside i32 range. - checked_
vec_ option_ vec_ u64_ into_ sexp - Convert
Vec<Option<Vec<u64>>>to an R list of integer vectors (None→NULL), panicking if any element of any row exceedsi32::MAX. - checked_
vec_ option_ vec_ usize_ into_ sexp - Convert
Vec<Option<Vec<usize>>>to an R list of integer vectors (None→NULL), panicking if any element of any row exceedsi32::MAX. - checked_
vec_ try_ from_ sexp_ i64 - Convert R SEXP to
Vec<i64>in strict mode. - checked_
vec_ try_ from_ sexp_ isize - Convert R SEXP to
Vec<isize>in strict mode. - checked_
vec_ 🔒try_ from_ sexp_ numeric - Generic strict vector conversion: only INTSXP and REALSXP allowed; an
NAelement is an error, like any other element that does not convert. - checked_
vec_ try_ from_ sexp_ u64 - Convert R SEXP to
Vec<u64>in strict mode. - checked_
vec_ try_ from_ sexp_ usize - Convert R SEXP to
Vec<usize>in strict mode. - checked_
vec_ u64_ into_ sexp - Convert
Vec<u64>to R integer vector, panicking if any element > i32::MAX. - checked_
vec_ usize_ into_ sexp - Convert
Vec<usize>to R integer vector, panicking if any element > i32::MAX. - checked_
vec_ vec_ i64_ into_ sexp - Convert
Vec<Vec<i64>>to an R list of integer vectors, panicking if any element of any row is outside i32 range. Every failing element is listed in one panic. - checked_
vec_ vec_ isize_ into_ sexp - Convert
Vec<Vec<isize>>to an R list of integer vectors, panicking if any element of any row is outside i32 range. - checked_
vec_ vec_ u64_ into_ sexp - Convert
Vec<Vec<u64>>to an R list of integer vectors, panicking if any element of any row exceedsi32::MAX. - checked_
vec_ vec_ usize_ into_ sexp - Convert
Vec<Vec<usize>>to an R list of integer vectors, panicking if any element of any row exceedsi32::MAX. - narrow 🔒
- Narrow a 64-bit value to the pointer-sized type, with the reason of a failure (only reachable on a 32-bit target).
- panic_
strict_ 🔒vec_ batched - Fold a batched strict-vec
BatchedErrorsinto the single panic everychecked_vec_*_into_sexpraises for the return value of Rust typecontainer(e.g."Vec<i64>"). - strict_
int_ 🔒elt - One INTSXP element:
NA_integer_isNone; any other value coerces. - strict_
real_ 🔒elt - One REALSXP element:
NA_real_isNone; any other value coerces, so a fractional, NaN or out-of-range double fails. - strict_
type_ 🔒error - The strict input-type gate: only INTSXP and REALSXP are accepted.