latexsnipper_runtime/factory.rs
1//! Runtime factory trait — creates sessions for a specific runtime kind.
2
3use crate::kind::RuntimeKind;
4use crate::{RuntimeArtifacts, RuntimeOptions, RuntimeProbe, RuntimeSession};
5use latexsnipper_foundation::Result;
6
7/// Factory for creating runtime sessions.
8///
9/// Each runtime kind has one factory. The factory is responsible for:
10/// 1. Probing availability on the current machine
11/// 2. Creating inference sessions from model artifacts
12///
13/// Factories are registered in the [`RuntimeRegistry`](crate::RuntimeRegistry).
14pub trait RuntimeFactory: Send + Sync {
15 /// Which runtime this factory creates sessions for.
16 fn kind(&self) -> RuntimeKind;
17
18 /// Probe whether this runtime is available on the current machine.
19 ///
20 /// Should be fast and never panic. Returns detailed availability info.
21 fn probe(&self) -> RuntimeProbe;
22
23 /// Create a new inference session.
24 ///
25 /// # Arguments
26 /// * `artifacts` - Model files and their roles for this runtime variant
27 /// * `options` - Runtime configuration (device, providers, threads, etc.)
28 fn create_session(
29 &self,
30 artifacts: &RuntimeArtifacts,
31 options: &RuntimeOptions,
32 ) -> Result<Box<dyn RuntimeSession>>;
33
34 /// Release factory-owned session caches. Most factories do not cache.
35 fn clear_sessions(&self) {}
36}