Skip to main content

VersionedState

Struct VersionedState 

Source
pub struct VersionedState<S> {
    pub version: u32,
    pub data: S,
}
Expand description

Version-tagged wrapper for serialized widget state.

When persisting state, the registry wraps the raw state in this envelope so it can detect schema version mismatches on restore.

§Serialization

With the state-persistence feature enabled, VersionedState derives Serialize and Deserialize. Without the feature, it is a plain struct usable for in-memory versioning.

Fields§

§version: u32

Schema version (from Stateful::state_version()).

§data: S

The actual state payload.

Implementations§

Source§

impl<S> VersionedState<S>

Source

pub fn new(version: u32, data: S) -> Self

Wrap state with its current version tag.

Source

pub fn pack<W: Stateful<State = S>>(widget: &W) -> Self

Pack a widget’s state into a versioned envelope.

Source

pub fn unpack<W: Stateful<State = S>>(self) -> Option<S>

Attempt to unpack, returning None if the version does not match the widget’s current state_version().

Source

pub fn unpack_or_default<W: Stateful<State = S>>(self) -> S
where S: Default,

Unpack with fallback: returns the stored data if versions match, otherwise returns S::default().

Source§

impl<S> VersionedState<S>

Source

pub fn unpack_with_migration<W>( self, chain: &MigrationChain<S>, ) -> RestoreResult<S>
where W: Stateful<State = S>, S: Default + 'static + Send,

Attempt to unpack with migration support.

If the stored version doesn’t match the current version, attempts to migrate through the provided chain. Falls back to default on failure.

§Type Parameters
  • W: The widget type that implements Stateful<State = S>.
§Example
let chain = MigrationChain::new();
// ... register migrations ...

let versioned = load_state_from_disk();
let result = versioned.unpack_with_migration::<MyWidget>(&chain);
let state = result.into_state();

Trait Implementations§

Source§

impl<S: Clone> Clone for VersionedState<S>

Source§

fn clone(&self) -> VersionedState<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug> Debug for VersionedState<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S: Default> Default for VersionedState<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for VersionedState<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for VersionedState<S>
where S: RefUnwindSafe,

§

impl<S> Send for VersionedState<S>
where S: Send,

§

impl<S> Sync for VersionedState<S>
where S: Sync,

§

impl<S> Unpin for VersionedState<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for VersionedState<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for VersionedState<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more