Expand description
Vtable static generation, C wrapper generation, and method attribute parsing for trait impls.
This module contains the core codegen for #[miniextendr] on impl Trait for Type blocks.
It produces the vtable static constant, C-callable wrapper functions for each method and
associated constant, and delegates to super::r_wrappers for R wrapper code generation.
Re-exports§
use proc_macro2::TokenStream;🔒use quote::format_ident;🔒use syn::ItemImpl;🔒use super::r_wrappers::TraitWrapperOpts;🔒use super::r_wrappers::binds_trait_namespace;🔒use super::r_wrappers::generate_trait_r_wrapper;🔒use super::TraitAbiMetadata;🔒use super::TraitConst;🔒use super::TraitMethod;🔒use super::type_to_symbol_name;🔒use crate::miniextendr_impl::ClassSystem;🔒use crate::miniextendr_impl::ImplAttrs;🔒
Structs§
- Renamed
Param 🔒 - One parameter of an impl method, which the wrappers name as the declaration does.
- Trait
Method 🔒Attrs - Parsed
#[miniextendr(...)]attributes for a single trait method.
Functions§
- check_
r_ 🔒code_ uses_ declared_ names - Refuse a method’s R code (
r_entry,r_post_checks,r_on_exit, adefaults(...)value) that uses a parameter by the impl’s name where the wrapper’s formal has the declaration’s: R would find no such variable when the wrapper runs. - check_
trait_ 🔒method_ defaults - Reject a
defaults(...)entry that names no parameter of the trait method, with the inherent-impl wording (a typo would otherwise drop the default without a word). - declared_
param_ 🔒names - The parameter names the declaration’s metadata gives
method, in order. The metadata names every parameter (arg<i>for a declaration pattern). - extract_
consts 🔒 - Extract associated constant items from a trait impl block.
- extract_
methods 🔒 - Extract all methods from a trait impl block as
TraitMethodstructs. - generate_
concrete_ 🔒vtable_ shims - Generate concrete vtable shims for a generic trait impl.
- generate_
impl_ 🔒vtable - Reproduce the declaration’s repr(C) layout locally, with its exact field order and callback types. The versioned declaration tag guards the cast to the consumer’s nominal vtable type. The exported static’s name and byte representation stay the same for native and wasm registration.
- generate_
trait_ 🔒const_ c_ wrapper - Generate a C wrapper function and
R_CallMethodDeffor a trait associated constant. - generate_
trait_ 🔒method_ c_ wrapper - Generate a C wrapper function and
R_CallMethodDeffor a single trait method. - generate_
vtable_ 🔒static - Generate the vtable static, C wrappers, R wrappers, and call defs for a trait implementation.
- inherit_
method_ 🔒metadata - Inherit only declaration-level R naming/export metadata. The implementation owns its execution options, docs and signatures; an explicit impl rename wins, while a declaration’s skipped method is never exported accidentally.
- name_
params_ 🔒as_ declared - Name every parameter of
sig, a copy of an impl method’s signature, as the declaration’s metadata does (declared;arg<i>for a declaration pattern), so every impl of a trait has the same R formals and argument errors. Without the declaration’s names, or with another count, which rustc refuses, a named parameter keeps its name and a pattern becomesarg<i>. A name already taken gets a_suffix. Returns each parameter’s names, in order. - parse_
trait_ 🔒method_ attrs - Parse
#[miniextendr(...)]attributes from a trait method. - rekey_
params 🔒 options, keyed by parameter names as the impl method spells them, keyed by the declared names. A key may also be the declared name already; one that names no parameter stays, for the caller’s check to refuse. Naming one parameter both ways is an error atspan.