Skip to main content

TraitBridgeConfig

Struct TraitBridgeConfig 

Source
pub struct TraitBridgeConfig {
Show 13 fields pub trait_name: String, pub super_trait: Option<String>, pub registry_getter: Option<String>, pub register_fn: Option<String>, pub unregister_fn: Option<String>, pub clear_fn: Option<String>, pub type_alias: Option<String>, pub param_name: Option<String>, pub register_extra_args: Option<String>, pub exclude_languages: Vec<String>, pub bind_via: BridgeBinding, pub options_type: Option<String>, pub options_field: Option<String>,
}
Expand description

Configuration for generating trait bridge code that allows foreign language objects to implement Rust traits via FFI.

Fields§

§trait_name: String

Name of the Rust trait to bridge (e.g., "OcrBackend").

§super_trait: Option<String>

Super-trait that requires forwarding (e.g., "Plugin"). When set, the bridge generates an impl SuperTrait for Wrapper block.

§registry_getter: Option<String>

Rust path to the registry getter function (e.g., "kreuzberg::plugins::registry::get_ocr_backend_registry"). Optional — when set, the generated registration function inserts the bridge into a registry.

§register_fn: Option<String>

Name of the registration function to generate (e.g., "register_ocr_backend"). Optional — when set, a #[pyfunction] registration function is generated. When absent, only the wrapper struct and trait impl are emitted (per-call bridge pattern).

§unregister_fn: Option<String>

Name of the unregister function to generate (e.g., "unregister_ocr_backend"). Optional — when set, a host-language wrapper that removes a previously registered plugin from the registry is emitted alongside register_fn. The function takes the plugin name as a string.

§clear_fn: Option<String>

Name of the clear function to generate (e.g., "clear_ocr_backends"). Optional — when set, a host-language wrapper that removes ALL registered plugins of this type is emitted alongside register_fn. The function takes no arguments and is typically used in test teardown.

§type_alias: Option<String>

Named type alias in the IR that maps to this bridge (e.g., "VisitorHandle").

When a function parameter has a TypeRef::Named matching this alias, code generators replace the parameter type with the language-native callback object (e.g., Py<PyAny> for Python) and emit wrapping code to construct the bridge.

§param_name: Option<String>

Parameter name override — when the extractor sanitizes the type (e.g., VisitorHandle becomes String because it is a type alias over Rc<RefCell<dyn Trait>>), use the parameter name instead of the IR type to detect which parameter to bridge.

For example, param_name = "visitor" ensures that a sanitized visitor: Option<String> parameter is still treated as a bridge param for this trait.

§register_extra_args: Option<String>

Extra arguments to append to the registry.register(arc, ...) call. Example: "0" produces registry.register(arc, 0).

§exclude_languages: Vec<String>

Language backends that should NOT generate this trait bridge. Use backend names as they appear in Backend::name(), e.g. ["elixir", "wasm"]. When a backend’s name is listed here, the bridge struct and all related code are omitted from that backend’s output.

§bind_via: BridgeBinding

How the bridge attaches to the public API.

  • "function_param" (default): the bridge object arrives as a function argument at the position of any param_name-matching parameter. This is the legacy mode.
  • "options_field": the bridge object lives as a field on a configured options struct that itself arrives as a function argument. Backends emit a host-language field on that struct instead of a separate function parameter; the bridge object is attached to options.<field> before the underlying core call.
§options_type: Option<String>

IR type name that owns the bridge field when bind_via = "options_field" (e.g., "ConversionOptions"). Required in that mode; ignored otherwise.

§options_field: Option<String>

Field name on options_type that holds the bridge handle when bind_via = "options_field" (e.g., "visitor"). When omitted, defaults to param_name. Ignored when bind_via = "function_param".

Implementations§

Source§

impl TraitBridgeConfig

Source

pub fn resolved_options_field(&self) -> Option<&str>

Resolve the field name on options_type that holds this bridge.

Falls back to Self::param_name when Self::options_field is unset, matching the convention that the field name and parameter name are the same in most cases. Returns None if neither is set.

Trait Implementations§

Source§

impl Clone for TraitBridgeConfig

Source§

fn clone(&self) -> TraitBridgeConfig

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 TraitBridgeConfig

Source§

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

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

impl Default for TraitBridgeConfig

Source§

fn default() -> TraitBridgeConfig

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

impl<'de> Deserialize<'de> for TraitBridgeConfig

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 TraitBridgeConfig

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<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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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 = Infallible

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,