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 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_lowlevelFlagSuppress automatic impl_alt*_from_data! macro invocation. 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. Only supported for integer and complex 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 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 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 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.

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.

There are two code generation paths:

  1. Simple path – When using the default RUnwind guard and no subset option, delegates to the impl_alt*_from_data! runtime macro which bundles Altrep, AltVec, family-specific methods, and InferBase in a single expansion.

  2. Expanded path – When a non-default guard mode or subset is 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§

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> 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