twine_core/model.rs
1/// A callable model that maps a typed input to a typed output.
2///
3/// Models must be deterministic, always producing the same result for a given
4/// input, which makes them a stable foundation for solvers, simulations,
5/// caching, and instrumentation.
6pub trait Model {
7 type Input;
8 type Output;
9 type Error: std::error::Error + Send + Sync + 'static;
10
11 /// Calls the model with the given input.
12 ///
13 /// # Errors
14 ///
15 /// Each model defines its own `Error` type to represent domain-specific failures.
16 fn call(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>;
17}
18
19/// A captured input/output pair from a model call.
20#[derive(Debug, Clone, Copy)]
21pub struct Snapshot<I, O> {
22 pub input: I,
23 pub output: O,
24}
25
26impl<I, O> Snapshot<I, O> {
27 /// Creates a new snapshot from input and output values.
28 pub fn new(input: I, output: O) -> Self {
29 Self { input, output }
30 }
31}