Skip to main content

Module trait_bridge

Module trait_bridge 

Source
Expand description

Shared trait bridge code generation.

Generates wrapper structs that allow foreign language objects (Python, JS, etc.) to implement Rust traits via FFI. Each backend implements TraitBridgeGenerator to provide language-specific dispatch logic; the shared functions in this module handle the structural boilerplate.

Structs§

BridgeOutput
Result of trait bridge generation: imports (to be added via builder.add_import) and the code body (to be added via builder.add_item).
TraitBridgeSpec
Everything needed to generate a trait bridge for one trait.

Traits§

TraitBridgeGenerator
Backend-specific trait bridge generation.

Functions§

format_param_type
Format a parameter type, respecting is_ref, is_mut, and optional from the IR.
format_return_type
Format a return type, wrapping in Result when an error type is present.
format_type_ref
Format a TypeRef as a Rust type string for use in trait method signatures.
gen_bridge_all
Generate the complete trait bridge code block: struct, impls, and optionally a registration function.
gen_bridge_plugin_impl
Generate impl SuperTrait for Wrapper when the bridge config specifies a super-trait.
gen_bridge_registration_fn
Generate the register_xxx() function that wraps a foreign object and inserts it into the plugin registry.
gen_bridge_trait_impl
Generate impl Trait for Wrapper dispatching each method through the generator.
gen_bridge_wrapper_struct
Generate the wrapper struct holding the foreign object and cached fields.