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,
}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 impl_alt*_from_data! registration is still emitted automatically — you do not need to call it yourself. Use no_lowlevel as an additional escape hatch if you also want to suppress the registration. |
no_lowlevel | Flag | Suppress automatic impl_alt*_from_data! macro invocation. 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. |
subset | Flag | Enable Extract_subset method registration. Mutually exclusive with dataptr. Only supported for integer and complex families. Not supported for List. |
unsafe | Flag | Set guard mode to Unsafe – no panic protection on ALTREP callbacks. |
rust_unwind | Flag | Set guard mode to RustUnwind – uses catch_unwind only (unsafe if callbacks call 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 impl_alt*_from_data! macro call. 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.
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 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 has_non_default_guard(&self) -> bool
fn has_non_default_guard(&self) -> bool
Returns true if a non-default guard mode is set (i.e., Unsafe or RUnwind).
The default guard is RUnwind, which uses the simple impl_alt*_from_data!
macro path. Non-default guards (e.g., RustUnwind, Unsafe) require the
expanded code generation path that emits individual internal macros with an
explicit guard parameter.
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.
There are two code generation paths:
-
Simple path – When using the default
RUnwindguard and nosubsetoption, delegates to theimpl_alt*_from_data!runtime macro which bundlesAltrep,AltVec, family-specific methods, andInferBasein a single expansion. -
Expanded path – When a non-default guard mode or
subsetis requested, emits individual internal macros (__impl_altrep_base!,__impl_altvec_*!,__impl_alt*_methods!,impl_inferbase_*!) with explicit guard parameters.
§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).
Auto Trait Implementations§
impl Freeze for AltrepAttrs
impl RefUnwindSafe for AltrepAttrs
impl !Send for AltrepAttrs
impl !Sync 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> 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: 184 bytes