Skip to main content

SystemState

Struct SystemState 

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

A heterogeneous collection of payloads describing one system time point.

Fields are declared by a JSON-derived StateSpec. Values are addressed by those field names but stored in compact optional slots. The type-erased representation remains private; callers always insert, borrow, mutate, and extract concrete Rust types.

Implementations§

Source§

impl SystemState

Source

pub fn empty(&self, time: TimePoint) -> Self

Creates another empty state with the same shared specification.

No payload is cloned. Only the immutable specification handle is cloned, which increments an internal Arc reference count.

Source

pub const fn time(&self) -> TimePoint

Returns this state’s temporal coordinate.

Source

pub const fn spec(&self) -> &StateSpec

Returns the shared immutable field specification.

Source

pub fn len(&self) -> usize

Returns the number of fields declared by the state specification.

This count is structural and includes empty payload slots.

Source

pub fn is_empty(&self) -> bool

Reports whether the state specification declares no fields.

This is consistent with SystemState::len. To test whether a non-empty layout currently carries no payloads, use SystemState::is_blank.

Source

pub fn loaded(&self) -> usize

Returns the number of slots that currently contain payloads.

Source

pub fn is_blank(&self) -> bool

Reports whether every declared payload slot is empty.

Source

pub fn fields(&self) -> &[FieldSpec]

Returns field specifications in deterministic template order.

Source

pub fn has(&self, key: &str) -> Result<bool, StateError>

Reports whether a declared field currently contains a payload.

§Errors

Returns StateError::UnknownField when key was not declared by the JSON template.

Source

pub fn is<T>(&self, key: &str) -> Result<bool, StateError>
where T: Any,

Reports whether a populated field contains the exact Rust type T.

An empty declared field returns false.

§Errors

Returns StateError::UnknownField when key was not declared by the JSON template.

Source

pub fn set<T>(&mut self, key: &str, payload: T) -> Result<(), StateError>
where T: Any + Clone + Send,

Sets or replaces the payload in a declared field.

payload moves into the state and is never cloned. If the slot was already populated, its previous value is dropped. Call take first when the previous payload must be retained.

§Errors

Returns StateError::UnknownField when key was not declared by the JSON template. The payload is dropped with the returned error because this minimal API does not expose the internal erased-value wrapper.

Source

pub fn get<T>(&self, key: &str) -> Result<&T, StateError>
where T: Any,

Borrows a populated field as the exact Rust type T.

§Errors

Returns StateError::UnknownField for an undeclared key, StateError::MissingValue for an empty slot, or StateError::TypeMismatch when the stored concrete type differs from T.

Source

pub fn get_mut<T>(&mut self, key: &str) -> Result<&mut T, StateError>
where T: Any,

Mutably borrows a populated field as the exact Rust type T.

Mutation occurs in place and does not clone the payload.

§Errors

Returns StateError::UnknownField for an undeclared key, StateError::MissingValue for an empty slot, or StateError::TypeMismatch when the stored concrete type differs from T.

Source

pub fn take<T>(&mut self, key: &str) -> Result<T, StateError>
where T: Any + Send,

Removes and returns the payload from a declared field.

A successful call moves the original concrete T out of its internal box and leaves the field slot empty. It does not invoke Clone. If T does not match, the original erased value is restored before the error is returned.

§Errors

Returns StateError::UnknownField for an undeclared key, StateError::MissingValue for an empty slot, or StateError::TypeMismatch when the stored concrete type differs from T.

Source

pub fn clear(&mut self, key: &str) -> Result<bool, StateError>

Drops the payload stored in one declared field.

Returns true when a payload was present and dropped, or false when the declared slot was already empty.

§Errors

Returns StateError::UnknownField when key was not declared by the JSON template.

Source

pub fn clear_all(&mut self)

Drops every payload while retaining the shared layout and time point.

Trait Implementations§

Source§

impl Clone for SystemState

Source§

fn clone(&self) -> Self

Shares the immutable specification and deep-clones populated payloads.

1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SystemState

Source§

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

Formats structural metadata without formatting scientific payloads.

Auto Trait Implementations§

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, 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.