lash/plugin_binding.rs
1use crate::support::*;
2
3/// Typed app-facing activation for an ordinary Lash plugin.
4///
5/// A binding is not a second plugin implementation model. It gives embed hosts
6/// typed session configuration and typed per-turn input while still building
7/// a normal [`PluginFactory`] whose session plugin registers capabilities
8/// through `lash_core::PluginRegistrar`.
9///
10/// Plugin crates should expose a small domain extension trait over
11/// [`TurnBuilder`] for their turn input instead of asking app route code to
12/// call [`TurnBuilder::with_plugin_input`] directly:
13///
14/// ```ignore
15/// trait ToneTurnExt {
16/// fn with_tone(self, tone: Tone) -> Self;
17/// }
18///
19/// impl ToneTurnExt for lash::TurnBuilder {
20/// fn with_tone(self, tone: Tone) -> Self {
21/// self.with_plugin_input::<TonePlugin>(ToneInput { tone })
22/// }
23/// }
24/// ```
25pub trait PluginBinding: Send + Sync + 'static {
26 const ID: &'static str;
27 type SessionConfig: Clone + Send + Sync + 'static;
28 type Input: Clone + Send + Sync + 'static;
29
30 fn factory(config: &Self::SessionConfig) -> Arc<dyn PluginFactory>;
31
32 fn requires_turn_input(_config: &Self::SessionConfig) -> bool {
33 false
34 }
35}
36
37#[derive(Clone, Debug)]
38pub(crate) struct ActivePluginBinding {
39 pub(crate) id: &'static str,
40 pub(crate) requires_turn_input: bool,
41}