pub struct StateSchemaUpgrade { /* private fields */ }Expand description
One directed application-schema upgrade a codec declares.
An upgrade rewrites a JSON-object payload recorded at from
into the shape to expects. The framework, not the codec,
selects and applies the edges, so a codec never inspects a recorded version
to decide what an older payload meant.
Edges strictly increase the version and at most one edge may leave any version, which is what makes a resolved chain deterministic and bounded.
Implementations§
Source§impl StateSchemaUpgrade
impl StateSchemaUpgrade
Sourcepub fn new(
from: StateSchemaVersion,
to: StateSchemaVersion,
apply: fn(&[u8]) -> Result<Vec<u8>, StateCodecError>,
) -> Result<Self, StateError>
pub fn new( from: StateSchemaVersion, to: StateSchemaVersion, apply: fn(&[u8]) -> Result<Vec<u8>, StateCodecError>, ) -> Result<Self, StateError>
Declares a directed upgrade between two application schema versions.
apply must be deterministic: the same payload bytes must always
produce the same result, because a restart replays the same chain over
the same durable bytes.
§Errors
Returns StateError::NonIncreasingUpgrade when to does not exceed
from, which would let a chain loop or move backwards.
Sourcepub const fn from(&self) -> StateSchemaVersion
pub const fn from(&self) -> StateSchemaVersion
Returns the version this upgrade reads.
Sourcepub const fn to(&self) -> StateSchemaVersion
pub const fn to(&self) -> StateSchemaVersion
Returns the version this upgrade produces.
Trait Implementations§
Source§impl Clone for StateSchemaUpgrade
impl Clone for StateSchemaUpgrade
Source§fn clone(&self) -> StateSchemaUpgrade
fn clone(&self) -> StateSchemaUpgrade
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more