Skip to main content

AltrepAttrs

Struct AltrepAttrs 

Source
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

KeyTypeDescription
len = "field"StringName of the struct field that holds the vector length. Auto-detected if a field is named len or length.
elt = "field"StringName 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.
manualFlagSkip 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_lowlevelFlagSuppress the automatic low-level trait impls. Use this when you want to provide your own Altrep, AltVec, and family-specific trait implementations.
dataptrFlagEnable Dataptr method registration, allowing R to get a direct pointer to the underlying data. Mutually exclusive with subset. Not supported for List.
serializeFlagEnable Serialized_state and Unserialize method registration for ALTREP serialization support.
subsetFlagEnable Extract_subset method registration. Mutually exclusive with dataptr. Supported on all atomic families. Not supported for List.
unsafeFlagSet guard mode to Unsafe – no panic protection on ALTREP callbacks.
rust_unwindFlagSet guard mode to RustUnwind – uses catch_unwind only (unsafe if callbacks call R APIs).
r_unwindFlagSet guard mode to RUnwind (default) – uses with_r_unwind_protect for safe R API calls.
class = "name"StringOverride 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: bool

Whether 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 protection
  • RustUnwindcatch_unwind only
  • RUnwindwith_r_unwind_protect (default)
§class_name: Option<String>

Override the ALTREP class name. Default: struct name.

§manual: bool

Manual mode: skip AltrepLen and Alt*Data generation. User provides their own. Set by #[altrep(manual)]. Lowlevel traits + registration still generated.

Implementations§

Source§

impl AltrepAttrs

Source

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.

Source

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.

Source

fn has_non_default_guard(&self) -> bool

Returns true if a non-default guard mode is set (i.e., Unsafe or RustUnwind).

The default guard is RUnwind. Non-default guards (e.g., RustUnwind, Unsafe) suppress the materializing-dataptr AltVec impl on the no-option arm (behaviour preserved from the pre-#711 expanded path).

Source

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:

  1. subset is only valid for families where supports_subset is true.
  2. dataptr and subset are mutually exclusive.
§Arguments
  • family – A human-readable family name used in error messages (e.g., "AltrepList").
  • supports_subset – Whether this family supports the Extract_subset method.
§Errors

Returns Err with a span pointing to the offending option identifier.

Source

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:

  1. __impl_altrep_base!(Ty, <guard>[, with_serialize])impl Altrep.
  2. an AltVec impl, one of:
    • materializing (materializing_dataptr_macro) — default/serialize arms,
    • direct dataptr (__impl_altvec_dataptr!(Ty, <elem>); string routes through __impl_altvec_string_dataptr!) — dataptr arm,
    • subset (__impl_altvec_extract_subset!) — subset arm,
  3. methods_macro!(Ty) — the family Alt<Family> impl,
  4. 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§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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