Skip to main content

MethodAttrs

Struct MethodAttrs 

Source
pub struct MethodAttrs {
Show 26 fields pub ignore: bool, pub constructor: bool, pub r6: R6MethodAttrs, pub as_coercion: Option<String>, pub as_coercion_span: Option<Span>, pub generic: Option<String>, pub class: Option<String>, pub worker: bool, pub unsafe_main_thread: bool, pub check_interrupt: bool, pub coerce: bool, pub rng: bool, pub unwrap_in_r: bool, pub defaults: HashMap<String, String>, pub defaults_span: Option<Span>, pub per_param: HashMap<String, ParamAttrs>, pub match_arg_span: Option<Span>, pub s7: S7MethodAttrs, pub lifecycle: Option<LifecycleSpec>, pub vctrs_protocol: Option<String>, pub r_name: Option<String>, pub r_entry: Option<String>, pub r_post_checks: Option<String>, pub r_on_exit: Option<ROnExit>, pub internal: bool, pub noexport: bool,
}
Expand description

Per-method attributes for class system customization.

Fields§

§ignore: bool

Skip this method

§constructor: bool

Mark as constructor

§r6: R6MethodAttrs

R6-specific method markers. All R6 boolean flags live here. Only consumed by the R6 class generator and R6-aware accessor methods (ParsedMethod::is_active, is_private, is_finalizer).

§as_coercion: Option<String>

Generate as as.<class>() S3 method (e.g., “data.frame”, “list”, “character”).

When set, generates an S3 method for R’s as.<class>() generic:

as.data.frame.MyType <- function(x, ...) {
    .Call(C_MyType__as_data_frame, .call = match.call(), x)
}

Valid values: data.frame, list, character, numeric, double, integer, logical, matrix, vector, factor, Date, POSIXct, complex, raw, environment, function

§as_coercion_span: Option<Span>

Span of as = "..." for error reporting.

§generic: Option<String>

Override generic name for S3/S4/S7 methods.

Use this to implement methods for existing generics (like print, format, length) without creating a new generic. When set, the generated code:

  • Uses the specified generic name instead of the method name
  • Skips creating a new generic (assumes it already exists)
  • Creates only the method implementation (e.g., print.MyClass)

§Example

#[miniextendr(s3)]
impl MyType {
    #[miniextendr(generic = "print")]
    fn show(&self) -> String {
        format!("MyType: {}", self.value)
    }
}

This generates print.MyType that calls the show method.

§class: Option<String>

Override class suffix for S3 methods.

Use this to implement double-dispatch methods (like vctrs coercion) where the class suffix differs from the type name or contains multiple classes.

§Example

#[miniextendr(s3(generic = "vec_ptype2", class = "my_vctr.my_vctr"))]
fn ptype2_self(x: Robj, y: Robj, dots: ...) -> Robj {
    // Return prototype
}

This generates vec_ptype2.my_vctr.my_vctr for vctrs double-dispatch.

§worker: bool

Worker thread execution (default: auto-detect based on types)

§unsafe_main_thread: bool

Force main thread execution (unsafe)

§check_interrupt: bool

Enable R interrupt checking

§coerce: bool

Enable coercion for this method’s parameters

§rng: bool

Enable RNG state management (GetRNGstate/PutRNGstate)

§unwrap_in_r: bool

Return Result<T, E> to R without unwrapping.

§defaults: HashMap<String, String>

Parameter defaults from #[miniextendr(defaults(param = "value", ...))]

§defaults_span: Option<Span>

Span of defaults(...) for error reporting.

§per_param: HashMap<String, ParamAttrs>

Per-parameter match_arg / several_ok / choices state for this method, keyed by the Rust parameter name.

Method-level (not parameter-level) because Rust’s parser rejects attribute macros on fn parameters inside impl items. Standalone functions take the per-param syntax directly; impl methods spell the same data through #[miniextendr(match_arg(p1, p2))], #[miniextendr(match_arg_several_ok(p))], and #[miniextendr(choices(p = "a, b"))] on the method attribute.

Uses the shared ParamAttrs struct — the coerce / default fields are unused on the impl path.

§match_arg_span: Option<Span>

Span of match_arg(...) / choices(...) for error reporting.

§s7: S7MethodAttrs

S7-specific method markers. Only consumed by the S7 class generator; all other generators ignore this field.

§lifecycle: Option<LifecycleSpec>

Lifecycle specification for deprecation/experimental status on methods.

Use #[miniextendr(lifecycle = "deprecated")] or #[miniextendr(lifecycle(stage = "deprecated", when = "0.4.0", with = "new_method()"))] on methods in impl blocks.

§Example

#[miniextendr(r6)]
impl MyType {
    #[miniextendr(lifecycle = "deprecated")]
    pub fn old_method(&self) -> i32 { 0 }
}
§vctrs_protocol: Option<String>

vctrs protocol method override.

Use #[miniextendr(vctrs(format))] to mark a method as implementing a vctrs protocol S3 generic. The method will be generated as format.<class> instead of the default Rust method name.

Supported protocols: format, vec_proxy, vec_proxy_equal, vec_proxy_compare, vec_proxy_order, vec_restore, obj_print_data, obj_print_header, obj_print_footer.

§r_name: Option<String>

Override R method name.

Use #[miniextendr(r_name = "add_one")] to give the R method a different name than the Rust method. The C symbol is still derived from the Rust name. Cannot be combined with generic = "..." on the same method.

§r_entry: Option<String>

R code to inject at the very top of the method body (before all built-in checks).

§r_post_checks: Option<String>

R code to inject after all built-in checks, immediately before .Call().

§r_on_exit: Option<ROnExit>

Register on.exit() cleanup code in the R method wrapper.

Short form: #[miniextendr(r_on_exit = "close(con)")] Long form: #[miniextendr(r_on_exit(expr = "close(con)", add = false))]

§internal: bool

Mark this method as internal: adds @keywords internal, suppresses export.

For R6 active bindings this emits #' @field name (internal) so the binding stays satisfied for roxygen2 (which warns on undocumented R6 bindings even when @field name NULL is present) but is clearly marked internal in the docs.

§noexport: bool

Suppress export for this method without adding @keywords internal.

For R6 active bindings this emits #' @field name (internal) (see internal above for why we don’t use roxygen2’s @field name NULL opt-out).

Trait Implementations§

Source§

impl Debug for MethodAttrs

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MethodAttrs

Source§

fn default() -> MethodAttrs

Returns the “default value” for a type. Read more

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