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: boolSkip this method
constructor: boolMark as constructor
r6: R6MethodAttrsR6-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: boolWorker thread execution (default: auto-detect based on types)
unsafe_main_thread: boolForce main thread execution (unsafe)
check_interrupt: boolEnable R interrupt checking
coerce: boolEnable coercion for this method’s parameters
rng: boolEnable RNG state management (GetRNGstate/PutRNGstate)
unwrap_in_r: boolReturn 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: S7MethodAttrsS7-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: boolMark 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: boolSuppress 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
impl Debug for MethodAttrs
Source§impl Default for MethodAttrs
impl Default for MethodAttrs
Source§fn default() -> MethodAttrs
fn default() -> MethodAttrs
Auto Trait Implementations§
impl Freeze for MethodAttrs
impl RefUnwindSafe for MethodAttrs
impl !Send for MethodAttrs
impl !Sync for MethodAttrs
impl Unpin for MethodAttrs
impl UnsafeUnpin for MethodAttrs
impl UnwindSafe for MethodAttrs
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: 704 bytes