Skip to main content

State

Struct State 

Source
pub struct State { /* private fields */ }
Expand description

The shared graph state: channel name → value, with copy-on-write sharing at channel granularity (R0.7 wave 4).

This is the “untyped typed-dict” of the engine: nodes read the full state snapshot and return partial updates keyed by channel name. Type safety for concrete applications is layered on top via serde (de)serialization of individual channel values.

§Copy-on-write representation

Every channel value sits behind an Arc, and the channel map itself behind another. Cloning a State — the executor’s per-super-step snapshot, each node’s private copy, the checkpoint’s copy — is two refcount bumps, O(1) in the state’s size, where it used to be a deep clone of every channel. A write (a reducer merge at the barrier, an engine State::insert) touches only what it must: the map is cloned shallowly when shared (one refcount bump per channel), and a channel’s value is cloned only when some other State still shares it — Arc::make_mut semantics per channel. Unchanged channels stay shared between the pre- and post-step states and every node’s snapshot, which is also what delta checkpoints diff against (see crate::checkpoint::encode_delta): sharing and deltas are the same structural observation.

The public contract is unchanged and pinned: State::get still returns Option<&Value>, serde still sees the same JSON object (the custom impls below serialize exactly like the previous transparent Map, so checkpoints, the wire, the SDKs, and golden files stay byte-identical), and reducer semantics are untouched. What changed is representation only.

Implementations§

Source§

impl State

Source

pub fn new() -> Self

An empty state.

Source

pub fn from_map(inner: Map<String, Value>) -> Self

Wrap an existing JSON object.

Source

pub fn from_value(value: Value) -> Result<Self>

Build a state from any serializable value that is a JSON object.

Source

pub fn to_value(&self) -> Value

Serialize the whole state back into a Value::Object.

Source

pub fn into_map(self) -> Map<String, Value>

Consume the state, returning the underlying map. Channel values that no other state shares are unwrapped without copying; shared ones are cloned (copy-on-write).

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &Value)>

Iterate over (channel, value) pairs.

Source

pub fn get(&self, channel: &str) -> Option<&Value>

Get a channel’s current value.

Source

pub fn contains(&self, channel: &str) -> bool

true if the channel exists in the state (regardless of value).

Source

pub fn insert(&mut self, channel: impl Into<String>, value: Value)

Directly set a channel’s value, bypassing reducer semantics.

Intended for engine internals (initial state seeding, checkpoint restore). Nodes should always go through reducers.

Source

pub fn get_as<T: DeserializeOwned>(&self, channel: &str) -> Result<Option<T>>

Deserialize a channel into a concrete type.

Source

pub fn len(&self) -> usize

Number of channels currently present.

Source

pub fn is_empty(&self) -> bool

true if no channels are present.

Trait Implementations§

Source§

impl Clone for State

Source§

fn clone(&self) -> State

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for State

Source§

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

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

impl Default for State

Source§

fn default() -> State

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

impl<'de> Deserialize<'de> for State

Parses any JSON object, as the previous transparent Map did.

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<Map<String, Value>> for State

Source§

fn from(inner: Map<String, Value>) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for State

Source§

fn eq(&self, other: &State) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for State

Serializes exactly like the Map<String, Value> this type used to wrap transparently: a JSON object of channel name → value. Byte-identity with the pre-W4 wire shape is the contract — checkpoints, goldens, and SDK payloads must not drift because the interior changed.

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for State

Auto Trait Implementations§

§

impl Freeze for State

§

impl RefUnwindSafe for State

§

impl Send for State

§

impl Sync for State

§

impl Unpin for State

§

impl UnsafeUnpin for State

§

impl UnwindSafe for State

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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