bb_runtime/roles/model.rs
1//! `ModelRuntime` - role trait for model implementations.
2//!
3//! Per `docs/ROLES.md` §5. The trait carries the universal pair
4//! (`atomic_opset` + `dispatch_atomic`); the engine routes through
5//! `dispatch_atomic`. Author Contract impls
6//! (`crate::contracts::Model`) define the user-facing surface;
7//! `#[derive(bb::Model)]` emits the bridge into
8//! `ModelRuntime::dispatch_atomic`.
9
10use crate::atomic::{AtomicOpsetDecl, DispatchResult};
11use crate::runtime::RuntimeResourceRef;
12use crate::slot_value::SlotValue;
13
14/// Role trait for model implementations.
15pub trait ModelRuntime: Send + Sync {
16 /// Model-impl-specific error type.
17 type Error: std::error::Error + Send + Sync + 'static;
18
19 /// Atomic-op opset this impl owns.
20 fn atomic_opset(&self) -> AtomicOpsetDecl;
21
22 /// Rust-dispatch entry point for atomic ops.
23 fn dispatch_atomic(
24 &mut self,
25 op_type: &str,
26 inputs: &[(&str, &dyn SlotValue)],
27 ctx: &mut RuntimeResourceRef<'_>,
28 ) -> Result<DispatchResult, Self::Error>;
29}