Skip to main content

FreezeThaw

Trait FreezeThaw 

pub trait FreezeThaw {
    // Required methods
    fn serialize_state(&self) -> Vec<u8> ⓘ;
    fn restore_state(&mut self, bytes: &[u8]) -> Result<(), ThawError>;

    // Provided methods
    fn capture_view(&self) -> View { ... }
    fn restore_view(&mut self, _view: &View) { ... }
    fn freeze(&self) -> Vec<u8> ⓘ { ... }
    fn thaw(&mut self, bytes: &[u8]) -> Result<(), ThawError> { ... }
}
Expand description

Freeze/thaw for a Tilo app, extendable at exactly one seam.

The two required methods are the override hook: serialize_state / restore_state say how an app’s state becomes bytes and back, defaulting (for a crate::app::App) to the CRDT doc.save() / AutoCommit::load; a non-CRDT app overrides only these.

capture_view / restore_view default to an empty View / a no-op, so an implementor that doesn’t touch the toolkit’s focus/scroll machinery still round-trips its state; crate::app::App overrides them for the real focus/scroll/resource/viewport.

freeze / thaw are not meant to be overridden: they frame serialize_state() + capture_view() into a versioned FrozenApp and back, so overriding the state hook changes only serialization.

Required Methods§

fn serialize_state(&self) -> Vec<u8> ⓘ

Serialize this app’s state to bytes. The single override point for a non-CRDT app.

fn restore_state(&mut self, bytes: &[u8]) -> Result<(), ThawError>

Load state bytes produced by serialize_state.

§Errors

Returns an error if bytes is not a payload this implementor previously produced via serialize_state — truncated, corrupt, or from an incompatible version.

Provided Methods§

fn capture_view(&self) -> View

Capture this app’s presentation into a View. Default: an empty View, so an implementor with no toolkit-managed presentation still round-trips.

fn restore_view(&mut self, _view: &View)

Restore a View onto this app. Default: no-op.

fn freeze(&self) -> Vec<u8> ⓘ

Serialize state and view into one versioned envelope. Not an override point — overriding serialize_state is enough to change what this produces.

fn thaw(&mut self, bytes: &[u8]) -> Result<(), ThawError>

Restore state and view from bytes produced by freeze.

§Errors

Returns an error — never panics — on truncated/garbage bytes, an unknown version, or an unloadable state payload.

Implementors§

§

impl FreezeThaw for App