Skip to main content

TraitMethodContext

Struct TraitMethodContext 

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

Reference to the parsed trait method metadata.

§c_ident: String

The C wrapper identifier string (e.g., "C_Foo__Bar__value"), used in .Call().

§params: String

R formals string with defaults, used in function(...) signatures.

§args: String

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

Source

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.

Source

pub(super) fn static_call(&self) -> String

Build the .Call() expression for a static (non-receiver) trait method.

Source

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.

Source

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.

Source

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.

Source

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§

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> SizeHint for T
where T: ?Sized,

Source§

default fn lower_bound(&self) -> usize

🔬This is a nightly-only experimental API. (core_io_internals)
Returns a lower bound on the number of elements this container-like item contains. For example, an array [u8; 12] could return any value between 0 and 12 inclusively as a correct implementation. Read more
Source§

default fn upper_bound(&self) -> Option<usize>

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an upper bound on the number of elements this container-like item contains if it can be determined, otherwise None. Read more
Source§

final fn size_hint(&self) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (core_io_internals)
Returns an estimate for the number of elements this container like type contains. Read more
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: 80 bytes