cranpose-core 0.9.6

Composition runtime and reactive state for Cranpose
Documentation

cranpose-core

cranpose-core provides the composition runtime, reactive state, composition locals, runtime scheduler support, and coroutine hooks used by Cranpose. Most application code uses these services through the cranpose facade.

Depend directly on cranpose-core when you build a host integration, a framework crate, or a lower-level runtime tool. App code with ordinary UI needs the facade and widget crates instead.

State and runtime

The host creates a Runtime with a scheduler. The runtime gives state a place to live and accepts snapshot commits. State changes mark subscribed scopes for recomposition.

use cranpose_core::{
    DefaultScheduler, Runtime, mutableStateOf, run_in_mutable_snapshot, scheduler_ref,
};

let _runtime = Runtime::new(scheduler_ref(DefaultScheduler));
let count = mutableStateOf(0);

assert_eq!(count.value(), 0);
let applied = run_in_mutable_snapshot(|| count.set(1));
assert!(applied.is_ok());
assert_eq!(count.value(), 1);

Composition code uses remember for values tied to a composition position and CompositionLocalProvider for scoped values. ownedMutableStateOf gives Rust owners an explicit state lifetime.

Features

The default feature set is empty. hot-reload selects source-structure keys for development hot reload. std-hash selects the standard library hasher.

Runtime structure

The slot table stores active groups, payloads, and nodes. Retained inactive branches use detached subtrees. See the slot table invariants and the current slot table design.