struct AltrepAttrs {
len_field: Option<Ident>,
elt_field: Option<Ident>,
elt_delegate: Option<Ident>,
generate_lowlevel: bool,
lowlevel_options: Vec<Ident>,
guard: Option<Ident>,
class_name: Option<String>,
manual: bool,
duplicate: Option<LitStr>,
}Expand description
Parsed #[altrep(...)] attributes controlling ALTREP derive code generation.
These attributes are placed on the struct and parsed by all ALTREP derive macros
(AltrepInteger, AltrepReal, etc.) to customize the generated trait implementations.
§Supported #[altrep(...)] keys
| Key | Type | Description |
|---|---|---|
len = "field" | String | Name of the struct field that holds the vector length. Auto-detected if a field is named len or length. |
elt = "field" | String | Name of the struct field to return as the element value (produces a constant-value vector). If omitted, the default elt() returns NA / NaN / 0 / None depending on the family. |
manual | Flag | Skip automatic AltrepLen and Alt*Data trait generation. Use when you want to write those trait impls by hand (e.g., for custom elt logic, no_na, sum, etc.). The low-level trait impls (Altrep, AltVec, family methods, InferBase) are still emitted automatically — you do not need to write them yourself. Use no_lowlevel as an additional escape hatch if you also want to suppress those. |
no_lowlevel | Flag | Suppress the automatic low-level trait impls. Use this when you want to provide your own Altrep, AltVec, and family-specific trait implementations. |
dataptr | Flag | Enable Dataptr method registration, allowing R to get a direct pointer to the underlying data. Mutually exclusive with subset. Not supported for List. |
serialize | Flag | Enable Serialized_state and Unserialize method registration for ALTREP serialization support. |
duplicate = "clone" | String | Keep ALTREP on duplication: clone the owner (requires Clone) and copy the R cache. Omission retains R’s default, which materializes an ordinary vector. |
subset | Flag | Enable Extract_subset method registration. Mutually exclusive with dataptr. Supported on all atomic families. Not supported for List. |
unsafe | Flag | Set native-read guard to Unsafe – no panic protection. Allocating bridges stay protected. |
rust_unwind | Flag | Set native-read guard to RustUnwind – catch_unwind only; reads must not call fallible R APIs. |
r_unwind | Flag | Set guard mode to RUnwind (default) – uses with_r_unwind_protect for safe R API calls. |
class = "name" | String | Override the ALTREP class name (default: struct name). |
Fields§
§len_field: Option<Ident>Field name containing the vector length, set via #[altrep(len = "field")].
If None, auto-detection looks for fields named len or length.
elt_field: Option<Ident>Field name for constant-value element access, set via #[altrep(elt = "field")].
When set, elt() returns self.{field} for every index.
elt_delegate: Option<Ident>Field name for delegated element access, set via #[altrep(elt_delegate = "field")].
When set, elt() calls self.{field}.elt(i), delegating to the inner type’s
AltIntegerData/AltRealData/etc. implementation. Useful for wrapper types
around StreamingIntData, StreamingRealData, etc.
generate_lowlevel: boolWhether to generate the low-level trait impls (Altrep, AltVec,
family methods, InferBase). Defaults to true. Set to false by
#[altrep(no_lowlevel)].
lowlevel_options: Vec<Ident>Collected option flags (dataptr, serialize, subset) passed to the runtime macro.
guard: Option<Ident>Guard mode override for ALTREP trampoline callbacks. Maps to AltrepGuard variants:
Unsafe– no protectionRustUnwind–catch_unwindonlyRUnwind–with_r_unwind_protect(default)
class_name: Option<String>Override the ALTREP class name. Default: struct name.
manual: boolManual mode: skip AltrepLen and Alt*Data generation. User provides their own.
Set by #[altrep(manual)]. Lowlevel traits + registration still generated.
duplicate: Option<LitStr>Opt-in duplicate policy; absent retains R’s materializing default.
Implementations§
Source§impl AltrepAttrs
impl AltrepAttrs
Sourcefn parse(input: &DeriveInput) -> Result<Self>
fn parse(input: &DeriveInput) -> Result<Self>
Parses all #[altrep(...)] attributes from a derive input struct.
Multiple #[altrep(...)] attributes are supported and their contents are merged.
Unknown keys produce a compile error.
§Errors
Returns Err if an #[altrep(...)] attribute has malformed syntax or contains
an unknown key.
Sourcefn duplicate_methods(&self) -> TokenStream
fn duplicate_methods(&self) -> TokenStream
Extra methods in the existing base impl; R’s DuplicateEX still copies attributes and object flags around this Duplicate hook.
Sourcefn get_len_field(&self, input: &DeriveInput) -> Result<Ident>
fn get_len_field(&self, input: &DeriveInput) -> Result<Ident>
Returns the length field identifier, either from the explicit len = "..." attribute
or by auto-detecting a field named len or length on the struct.
§Errors
Returns Err if the input is not a struct, or if no length field was specified
and auto-detection fails.
Sourcefn validate_options(&self, family: &str, supports_subset: bool) -> Result<()>
fn validate_options(&self, family: &str, supports_subset: bool) -> Result<()>
Validates that the requested #[altrep(...)] option flags are compatible with
the given ALTREP type family.
Enforces two rules:
subsetis only valid for families wheresupports_subsetistrue.dataptrandsubsetare mutually exclusive.
§Arguments
family– A human-readable family name used in error messages (e.g.,"AltrepList").supports_subset– Whether this family supports theExtract_subsetmethod.
§Errors
Returns Err with a span pointing to the offending option identifier.
Sourcefn generate_lowlevel(
&self,
name: &Ident,
generics: &Generics,
family: &AltrepFamilyConfig<'_>,
) -> Result<TokenStream>
fn generate_lowlevel( &self, name: &Ident, generics: &Generics, family: &AltrepFamilyConfig<'_>, ) -> Result<TokenStream>
Generates low-level ALTREP trait implementation code for a given type family.
Emits the underlying trait-impl macros directly (Path (a) from #682,
landed via #711/#933), reproducing the impl_alt<family>_from_data!
arm expansions from the proc-macro with no declarative-macro hop. The
four items every arm produces are:
__impl_altrep_base!(Ty, <guard>[, with_serialize])—impl Altrep.- an
AltVecimpl, one of:- materializing (
materializing_dataptr_macro) — default/serialize arms, - direct dataptr (
__impl_altvec_dataptr!(Ty, <elem>); string routes through__impl_altvec_string_dataptr!) —dataptrarm, - subset (
__impl_altvec_extract_subset!) —subsetarm,
- materializing (
methods_macro!(Ty)— the familyAlt<Family>impl,inferbase_macro!(Ty)—impl InferBase.
The guard is honoured uniformly (the retired declarative-macro
delegation only handled the default RUnwind guard; non-default guards
used a separate expanded path) and option combinations are validated
here at the derive call site rather than 7 hops deep in macro
expansion.
§Arguments
name– The struct identifier.family– The family-specific configuration controlling which macros to emit.
§Returns
A token stream containing the macro invocations, or an empty stream if
no_lowlevel was specified.
§Errors
Returns Err if option validation fails (e.g., subset on an
unsupported family, or dataptr combined with subset).
Auto Trait Implementations§
impl !Send for AltrepAttrs
impl !Sync for AltrepAttrs
impl Freeze for AltrepAttrs
impl RefUnwindSafe for AltrepAttrs
impl Unpin for AltrepAttrs
impl UnsafeUnpin for AltrepAttrs
impl UnwindSafe for AltrepAttrs
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> 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: 192 bytes