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§
- Bridge
Field Match - Match info for a trait bridge whose handle lives as a struct field
(
bind_via = "options_field"). - Bridge
Output - Result of trait bridge generation: imports (to be added via
builder.add_import) and the code body (to be added viabuilder.add_item). - Trait
Bridge Spec - Everything needed to generate a trait bridge for one trait.
Traits§
- Trait
Bridge Generator - Backend-specific trait bridge generation.
Functions§
- bridge_
param_ type - Map a
TypeRefto its Rust source type string for use in trait bridge method signatures.ciis the core import path (e.g."kreuzberg"),tpmaps type names to fully-qualified paths. - find_
bridge_ field - Find the first function parameter whose IR type carries a bridge field
(
bind_via = "options_field"). - find_
bridge_ param - Find the first function parameter that matches a trait bridge configuration (by type alias or parameter name).
- format_
param_ type - Format a parameter type, respecting
is_ref,is_mut, andoptionalfrom the IR. - format_
return_ type - Format a return type, wrapping in
Resultwhen an error type is present. - format_
type_ ref - Format a
TypeRefas 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_ clear_ fn - Generate the
clear_xxx()function that removes all registered plugins of this type. - gen_
bridge_ plugin_ impl - Generate
impl SuperTrait for Wrapperwhen 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 Wrapperdispatching each method through the generator. - gen_
bridge_ unregistration_ fn - Generate the
unregister_xxx(name)function that removes a previously registered plugin from the registry. - gen_
bridge_ wrapper_ struct - Generate the wrapper struct holding the foreign object and cached fields.
- host_
function_ path - Resolve the FQN of a host-crate plugin function (e.g.
kreuzberg::plugins::ocr::unregister_ocr_backend) given the bridge’sregistry_getterpath. The convention used by host crates is: - prim
- Map a Rust primitive to its type string.
- to_
camel_ case - Convert a snake_case string to camelCase.
- visitor_
param_ type - Map a visitor method parameter type to the correct Rust type string, handling IR quirks: