Skip to main content

coreml_native/
state.rs

1//! Stateful prediction support (MLState).
2//!
3//! Requires macOS 15+ / iOS 18+.
4//! Covers FR-5.1, FR-5.2, FR-5.3.
5
6#[cfg(target_vendor = "apple")]
7use objc2::rc::Retained;
8
9/// A persistent state for stateful CoreML models (RNN, KV-cache, etc.).
10///
11/// State is mutated in-place during prediction and carries forward
12/// across multiple predict calls.
13#[cfg(target_vendor = "apple")]
14pub struct State {
15    pub(crate) inner: Retained<objc2_core_ml::MLState>,
16}
17
18#[cfg(target_vendor = "apple")]
19impl std::fmt::Debug for State {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        f.debug_struct("State").finish()
22    }
23}
24
25#[cfg(target_vendor = "apple")]
26unsafe impl Send for State {}
27
28#[cfg(not(target_vendor = "apple"))]
29#[derive(Debug)]
30pub struct State {
31    _private: (),
32}