Struct StateBlob
pub struct StateBlob {
pub kind: String,
pub version: u32,
pub data: Value,
}Expand description
A typed, versioned piece of state persisted through storage.
This is the replacement for Optuna’s system_attrs junk drawer: sampler
and scheduler state is data,
not object innards. It is serializable, so it survives a process restart
and works across machines; it carries a kind and a version, so a
backend can refuse to hand a v1 blob to code expecting v2 instead of
deserializing garbage.
use atune_core::storage::StateBlob;
use serde::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct RungTable { rungs: Vec<u64> }
let blob = StateBlob::encode("asha", 1, &RungTable { rungs: vec![1, 3, 9] }).unwrap();
assert!(blob.is("asha", 1));
assert_eq!(blob.decode::<RungTable>().unwrap().rungs, vec![1, 3, 9]);Fields§
§kind: StringWhat produced the blob ("tpe", "asha", …). Namespaces the payload
inside a Scope.
version: u32The payload’s schema version, owned by whoever wrote it.
data: ValueThe payload.
Implementations§
§impl StateBlob
impl StateBlob
pub fn new(kind: impl Into<String>, version: u32, data: Value) -> Self
pub fn new(kind: impl Into<String>, version: u32, data: Value) -> Self
Wraps an already-serialized payload.
pub fn decode<T>(&self) -> Result<T>where
T: DeserializeOwned,
pub fn decode<T>(&self) -> Result<T>where
T: DeserializeOwned,
Deserializes the payload.
The caller is expected to have checked is first; a
blob written by a different producer will usually fail here rather than
silently decode.
§Errors
Error::Storage if the payload does
not match T.
pub fn ensure_schema_compatible(&self, replacement: &Self) -> Result<()>
pub fn ensure_schema_compatible(&self, replacement: &Self) -> Result<()>
Rejects replacing this blob with a different kind or schema version.
Lifecycle backends call this while holding their owner/transaction fence. A typed writer may replace the payload, but it must not replace an incompatible canonical blob and thereby erase data it cannot read.
§Errors
Error::Incompatible if the
replacement has a different kind or schema version.