pub struct MethodAttrs {Show 36 fields
pub ignore: bool,
pub constructor: bool,
pub force_invisible: Option<bool>,
pub r6: R6MethodAttrs,
pub as_coercion: Option<String>,
pub as_coercion_span: Option<Span>,
pub generic: Option<String>,
pub receiver: Option<String>,
pub no_dispatch_dots: bool,
pub class: Option<String>,
pub worker: bool,
pub unsafe_main_thread: bool,
pub check_interrupt: bool,
pub coerce: bool,
pub preconditions: Option<bool>,
pub rng: bool,
pub dots_spec: Option<TokenStream>,
pub dots_policy: Option<DotsPolicy>,
pub unwrap_in_r: bool,
pub serde_error: Option<SerdeErrorSpec>,
pub serialize: bool,
pub wrap: Option<ClassSystem>,
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 postfix: 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
force_invisible: Option<bool>invisible / visible method option (#1213): Some(true) makes the R
wrapper return invisible(...), Some(false) forces a visible return.
Same decision as an Invisible<T> / Visible<T> return-type marker;
the two must not disagree. Nothing is invisible by default.
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 = sys.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.
receiver: Option<String>First formal of an existing S3/S4 generic (for example object for show).
no_dispatch_dots: boolOmit the automatic dispatch dots for an existing S3/S4 generic.
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
preconditions: Option<bool>The method’s own preconditions / no_preconditions (bare; #1017,
#1566): Some(true) keeps the type-derived R-side checks of the
parameters that do not decide for themselves, Some(false) drops
them; the last one written wins. None defers to the impl block,
the crate default and the feature. The list forms
preconditions(p) / no_preconditions(p) land in
Self::per_param.
rng: boolEnable RNG state management (GetRNGstate/PutRNGstate)
dots_spec: Option<TokenStream>typed_list!(...) spec from #[miniextendr(dots = typed_list!(...))] on
this method, mirroring MiniextendrFnAttrs.dots_spec. When set, a
dots_typed binding is injected at the top of the method body. Per-method
(dots apply to an individual signature), not an impl-block-level option.
dots_policy: Option<DotsPolicy>What the method’s ... takes: dots = empty | empty(allow = [..]) | forward(allow = [..]) | data (#2157, crate::dots_policy), checked
in the R wrapper’s prelude
(emit_method_prelude).
unwrap_in_r: boolReturn Result<T, E> to R without unwrapping.
serde_error: Option<SerdeErrorSpec>Build the Err arm’s condition from the error’s serde output
(#[miniextendr(serde_error(shape = .., tag = .., prefix = .., ..))]).
serialize: boolSerialize the complete return value through AsSerialize<T>.
wrap: Option<ClassSystem>Explicit return class system (wrap = "r6" and siblings).
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))],
#[miniextendr(choices(p = "a, b"))],
#[miniextendr(no_default(p))] and
#[miniextendr(formal(p = "p.name"))] (#1842) 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.
postfix: Option<String>Append a fixed suffix to the Rust method name for the R-facing name
(#[miniextendr(postfix = "_impl")] on fn bump yields bump_impl).
Exclusive with r_name and generic; the C symbol is unchanged.
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 a class-level
#' @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 a class-level
#' @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
Auto Trait Implementations§
impl !Send for MethodAttrs
impl !Sync for MethodAttrs
impl Freeze for MethodAttrs
impl RefUnwindSafe 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> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§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: 1056 bytes