Skip to main content

RecordState

Trait RecordState 

pub trait RecordState:
    Sized
    + Send
    + Sync
    + 'static {
    // Required methods
    fn state_flatten(&self, prefix: &str, out: &mut StateSink);
    fn state_unflatten(
        prefix: &str,
        src: &mut StateSource,
        device: &Device,
    ) -> Option<Self>;
}
Expand description

A type that can be flattened into named tensors and scalars and rebuilt from them.

Generated with #[derive(RecordState)]. The prefix threads the parameter identity (and any nested field path) through the recursion; leaves are named {prefix}.{field}.

Required Methods§

fn state_flatten(&self, prefix: &str, out: &mut StateSink)

Flatten self into out, naming every leaf under prefix.

fn state_unflatten( prefix: &str, src: &mut StateSource, device: &Device, ) -> Option<Self>

Rebuild a value from src, reading leaves named under prefix.

Returns None when a required leaf is absent. The derive uses StateSource::has_under to presence-test optional nested states, so an Option<Nested> field is None exactly when nothing was recorded under its path.

A scalar leaf that is present but holds an incompatible [Scalar] variant (e.g. a hand-edited or forward-version file) is treated the same as absent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl RecordState for ()

The empty state — for stateless values (e.g. a constant learning rate scheduler).

§

fn state_flatten(&self, _prefix: &str, _out: &mut StateSink)

§

fn state_unflatten( _prefix: &str, _src: &mut StateSource, _device: &Device, ) -> Option<()>

Implementors§