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: boolTrue 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: boolTrue if the core function returns a reference (&T, Option<&T>, etc.).
Used by code generators to insert .clone() before type conversion.
returns_cow: boolTrue 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: boolTrue 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: boolTrue 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: VersionAnnotationVersion annotation (since, deprecated).
Implementations§
Source§impl MethodDef
impl MethodDef
Sourcepub fn returns_ref_to_owner(&self, owner_type_name: &str) -> bool
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.
Sourcepub fn cfg_satisfied(&self, enabled_features: &HashSet<&str>) -> bool
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_attribute — rustc resolves the gate for them, and unlike this
predicate it also honours non-feature leaves such as target_arch.
Sourcepub fn cfg_within(&self, owner_cfg: Option<&str>) -> Option<String>
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.
Sourcepub fn rust_cfg_attribute(&self) -> String
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<'de> Deserialize<'de> for MethodDef
impl<'de> Deserialize<'de> for MethodDef
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for MethodDef
impl RefUnwindSafe for MethodDef
impl Send for MethodDef
impl Sync for MethodDef
impl Unpin for MethodDef
impl UnsafeUnpin for MethodDef
impl UnwindSafe for MethodDef
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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