pub(super) struct TraitMethodContext<'a> {
pub(super) method: &'a TraitMethod,
pub(super) c_ident: String,
pub(super) params: String,
pub(super) args: String,
}Expand description
Pre-computed context for a trait method, mirroring MethodContext
(r_class_formatter.rs) for inherent-impl methods. Holds the C wrapper
name, R formals (with defaults), and .Call() argument string so all 5
trait generators build calls identically.
Fields§
§method: &'a TraitMethodReference to the parsed trait method metadata.
c_ident: StringThe C wrapper identifier string (e.g., "C_Foo__Bar__value"), used in .Call().
params: StringR formals string with defaults, used in function(...) signatures.
args: StringR call arguments string (without defaults), used inside .Call()
expressions. Missing<T> parameters are forwarded as
if (missing(p)) quote(expr=) else p — see
r_wrapper_builder::RArgumentBuilder::build_call_args_vec. Before this
context existed, trait methods built call args via
collect_param_idents instead, which skipped that forwarding entirely.
Implementations§
Source§impl<'a> TraitMethodContext<'a>
impl<'a> TraitMethodContext<'a>
Sourcepub(super) fn new(
method: &'a TraitMethod,
type_ident: &Ident,
trait_name: &Ident,
) -> Self
pub(super) fn new( method: &'a TraitMethod, type_ident: &Ident, trait_name: &Ident, ) -> Self
Build a context for method, which implements trait_name for type_ident.
Sourcepub(super) fn static_call(&self) -> String
pub(super) fn static_call(&self) -> String
Build the .Call() expression for a static (non-receiver) trait method.
Sourcepub(super) fn instance_call(&self, self_expr: &str) -> String
pub(super) fn instance_call(&self, self_expr: &str) -> String
Build the .Call() expression for an instance trait method, with
self_expr passed directly as the receiver argument (e.g. ".ptr",
"x", "self@.ptr").
This is the structured equivalent of MethodContext::instance_call —
no string surgery. It fixes the substring-corruption bug where S4/S7/R6
built the call with self = "x" and then ran
call.replace(", x", ", .ptr"): str::replace rewrites every match
of the substring ", x", so a parameter whose R name started with x
(e.g. x_factor) was corrupted into .ptr_factor, producing a runtime
“object ‘.ptr_factor’ not found” error. Passing the receiver expression
directly to with_self never touches the other arguments.
Sourcepub(super) fn match_arg_prelude(&self) -> Vec<String>
pub(super) fn match_arg_prelude(&self) -> Vec<String>
Build R prelude lines validating match_arg/choices params. See
r_class_formatter::build_match_arg_prelude.
Sourcepub(super) fn precondition_checks(&self) -> Vec<String>
pub(super) fn precondition_checks(&self) -> Vec<String>
R-side stopifnot() precondition checks for this method’s parameters.
See MethodContext::precondition_checks for the inherent-impl twin.
Sourcepub(super) fn emit_method_prelude(
&self,
lines: &mut Vec<String>,
indent: &str,
what: &str,
)
pub(super) fn emit_method_prelude( &self, lines: &mut Vec<String>, indent: &str, what: &str, )
Emit the shared method prelude into lines, each line prefixed with
indent — the trait-impl twin of MethodContext::emit_method_prelude.
In order: r_entry, r_on_exit, lifecycle_prelude,
precondition_checks, match_arg_prelude, r_post_checks.
Missing<T> forwarding is not a prelude step here either — it’s inline
in self.args (built in new), matching the inherent path.
what is the human-readable label passed to the lifecycle prelude.
This mirrors the pre-refactor trait_method_preamble_lines, which
always used the R-facing method name as what regardless of class
system (inherent methods instead use a class-qualified label like
"Type.method" — trait methods keep the simpler unqualified label to
avoid changing existing lifecycle-warning wording).
Auto Trait Implementations§
impl<'a> !Send for TraitMethodContext<'a>
impl<'a> !Sync for TraitMethodContext<'a>
impl<'a> Freeze for TraitMethodContext<'a>
impl<'a> RefUnwindSafe for TraitMethodContext<'a>
impl<'a> Unpin for TraitMethodContext<'a>
impl<'a> UnsafeUnpin for TraitMethodContext<'a>
impl<'a> UnwindSafe for TraitMethodContext<'a>
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: 80 bytes