1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use serde::{Deserialize, Serialize};
/// Configuration for generating trait bridge code that allows foreign language
/// objects to implement Rust traits via FFI.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TraitBridgeConfig {
/// Name of the Rust trait to bridge (e.g., `"OcrBackend"`).
pub trait_name: String,
/// Super-trait that requires forwarding (e.g., `"Plugin"`).
/// When set, the bridge generates an `impl SuperTrait for Wrapper` block.
#[serde(default)]
pub super_trait: 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.
#[serde(default)]
pub registry_getter: 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).
#[serde(default)]
pub register_fn: 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.
#[serde(default)]
pub type_alias: 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.
#[serde(default)]
pub param_name: Option<String>,
/// Extra arguments to append to the `registry.register(arc, ...)` call.
/// Example: `"0"` produces `registry.register(arc, 0)`.
#[serde(default)]
pub register_extra_args: Option<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.
#[serde(default)]
pub exclude_languages: Vec<String>,
}