Skip to main content

StateSubset

Trait StateSubset 

Source
pub trait StateSubset<Parent: State>: State {
    // Required methods
    fn extract(parent: &Parent) -> Self;
    fn map_update(update: Self::Update) -> Parent::Update;
}
Expand description

Compile-time constraint for shared-state subgraph mode

This trait defines the relationship between a parent graph’s state and a subgraph’s state when they share state fields. It enables type-safe state transformation between parent and child graphs.

§Type Parameters

  • Parent - The parent graph’s state type

§Examples

use juncture_core::State;

struct ParentState {
    name: String,
    age: u32,
}

struct ChildState {
    name: String,
}

impl StateSubset<ParentState> for ChildState {
    fn extract(parent: &ParentState) -> Self {
        Self { name: parent.name.clone() }
    }

    fn map_update(update: Self::Update) -> ParentState::Update {
        // Map child update to parent update
        ParentStateUpdate { name: update.name }
    }
}

Required Methods§

Source

fn extract(parent: &Parent) -> Self

Extract subgraph state from parent state

This method transforms the parent graph’s state into the subgraph’s state type, typically by copying or projecting relevant fields.

§Arguments
  • parent - Reference to the parent state
§Returns

The subgraph state

Source

fn map_update(update: Self::Update) -> Parent::Update

Map subgraph update to parent update

This method transforms a subgraph state update into a parent state update, allowing changes made in the subgraph to be applied to the parent graph’s state.

§Arguments
  • update - The subgraph’s state update
§Returns

The parent graph’s state update

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§