Skip to main content

MethodDef

Struct MethodDef 

Source
pub struct MethodDef {
Show 18 fields pub name: String, pub params: Vec<ParamDef>, pub return_type: TypeRef, pub is_async: bool, pub is_static: bool, pub error_type: Option<String>, pub doc: String, pub receiver: Option<ReceiverKind>, pub cfg: Option<String>, pub sanitized: bool, pub trait_source: Option<String>, pub returns_ref: bool, pub returns_cow: bool, pub return_newtype_wrapper: Option<String>, pub has_default_impl: bool, pub binding_excluded: bool, pub binding_exclusion_reason: Option<String>, pub version: VersionAnnotation,
}
Expand description

A method on a public struct.

Fields§

§name: String§params: Vec<ParamDef>§return_type: TypeRef§is_async: bool§is_static: bool§error_type: Option<String>§doc: String§receiver: Option<ReceiverKind>§cfg: Option<String>

#[cfg(...)] condition string on this method, AND-combined with its impl block’s own #[cfg(...)] (all(<impl>, <method>)).

One ApiSurface is extracted once and handed to every backend, each with its own features_for_language, so the gate cannot be resolved at extraction time — it must travel in the IR. Backends that generate Rust source re-emit it verbatim (MethodDef::rust_cfg_attribute); backends that emit a single host-language surface drop the method when their feature set does not satisfy it (crate::core::ir::ApiSurface::with_cfg_filtered_deep).

§sanitized: bool

True if any param or return type was sanitized during unknown type resolution. Methods with sanitized signatures cannot be auto-delegated.

§trait_source: Option<String>

Fully qualified trait path if this method comes from a trait impl (e.g. “sample_llm::LlmClient”). None for inherent methods.

§returns_ref: bool

True if the core function returns a reference (&T, Option<&T>, etc.). Used by code generators to insert .clone() before type conversion.

§returns_cow: bool

True if the core function returns Cow<'_, T> where T is a named type (not str/bytes). Used by code generators to emit .into_owned() before type conversion.

§return_newtype_wrapper: Option<String>

Full Rust path of the newtype wrapper that was resolved away for the return type, e.g. "my_crate::NodeIndex" when the return type NodeIndex(u32) was resolved to u32. When set, codegen must unwrap the returned newtype value (e.g. result.0) before returning.

§has_default_impl: bool

True if this method has a default implementation in the trait definition. Methods with defaults can be optionally implemented by the foreign object in trait bridge codegen.

§binding_excluded: bool

True when source metadata explicitly excludes this method from generated polyglot binding surfaces (via #[cfg_attr(alef, alef(skip))] or #[doc(hidden)]).

§binding_exclusion_reason: Option<String>

Human-readable reason for binding_excluded, used in diagnostics.

§version: VersionAnnotation

Version annotation (since, deprecated).

Implementations§

Source§

impl MethodDef

Source

pub fn returns_ref_to_owner(&self, owner_type_name: &str) -> bool

True when this is a static method that returns a borrowed reference to its own opaque owner type (e.g. Registry::global() -> &'static Registry).

The C FFI backend cannot box a borrow into an owned *mut T handle, so it never exports a {prefix}_{type}_{method} symbol for such accessors. Language backends (Java, C#, Zig) must consult this predicate so they do NOT bind a symbol the cdylib does not provide — otherwise eager symbol resolution (Java) crashes at class-init and lazy resolution (C#, Zig) fails on first call.

Keep this in lockstep with is_static_constructor in the FFI backend: that emitter skips static returns_ref methods, so every backend must agree on the absent symbol.

Source

pub fn cfg_satisfied(&self, enabled_features: &HashSet<&str>) -> bool

True when this method’s #[cfg(...)] gate is satisfied by enabled_features.

The sibling of Self::returns_ref_to_owner: a per-method predicate every backend consults, so the gate is evaluated in one place rather than re-derived at each emission site. Backends that generate Rust source should prefer Self::rust_cfg_attributerustc resolves the gate for them, and unlike this predicate it also honours non-feature leaves such as target_arch.

Source

pub fn cfg_within(&self, owner_cfg: Option<&str>) -> Option<String>

The #[cfg(...)] condition for an emitted item that also sits behind owner_cfg (its owning type’s or impl block’s gate): the AND of the two.

Identical gates collapse to one operand rather than all(X, X) — the common case, since a gated type is normally implemented in an impl block carrying the same gate, and a method inherits its block’s gate at extraction time.

Source

pub fn rust_cfg_attribute(&self) -> String

The #[cfg(...)] attribute line to emit above this method in generated Rust source, including the trailing newline; empty when the method is ungated.

Backends that emit Rust (FFI, pyo3, napi, magnus, rustler, Dart’s bridge crate) must re-emit the gate rather than filter on it: their generated crate is compiled with the core crate’s features, so rustc decides. Backends that emit a single host-language surface cannot express the gate and must filter instead.

Trait Implementations§

Source§

impl Clone for MethodDef

Source§

fn clone(&self) -> MethodDef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MethodDef

Source§

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

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

impl Default for MethodDef

Source§

fn default() -> MethodDef

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

impl<'de> Deserialize<'de> for MethodDef

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MethodDef

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more