Expand description
§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.
Re-exports§
pub extern crate self as cranpose_core;
Re-exports§
pub use concurrency::CollectEvents;pub use concurrency::CoroutineScope;pub use concurrency::Delay;pub use concurrency::EventChannel;pub use concurrency::EventSender;pub use concurrency::EventStream;pub use concurrency::EventStreamNext;pub use concurrency::ProduceScope;pub use concurrency::collectAsState;pub use concurrency::delay;pub use concurrency::interval;pub use concurrency::launchBlocking;pub use concurrency::produceState;pub use concurrency::rememberCoroutineScope;pub use concurrency::rememberEventStream;pub use concurrency::spawn_ui_task;pub use concurrency::withBlocking;pub use owned::Owned;pub use platform::Clock;pub use platform::RuntimeScheduler;pub use platform::SchedulerRef;pub use platform::scheduler_ref;pub use subcompose::ContentTypeReusePolicy;pub use subcompose::DefaultSlotReusePolicy;pub use subcompose::SlotId;pub use subcompose::SlotReusePolicy;pub use subcompose::SubcomposeState;pub use composer_context::note_nested_slots_host;pub use composer_context::with_composer as with_current_composer;pub use test_scratch::test_scratch_dir;
Modules§
- collections
- Collections the framework’s crates share: the hash map every crate uses, the bounded caches their hot paths keep, and the box that holds the properties few values set.
- composer_
context - concurrency
- Composition-scoped structured concurrency.
- env_
flags - Cached reads of the
CRANPOSE_*diagnostic environment variables. - hash
- owned
- platform
- Platform abstraction traits for Compose runtime services.
- runtime
- snapshot_
double_ index_ heap - snapshot_
id_ set - snapshot_
pinning - snapshot_
state_ observer - snapshot_
v2 - Snapshot system for managing isolated state changes.
- source_
trace - Optional composition origins for development tools.
- subcompose
- State tracking for measure-time subcomposition.
- test_
scratch - Where a test writes real files. Behind
test-helpersso only a test build of the workspace carries it. Where a test writes real files.
Macros§
- clone_
captures - env_
flag - Reads a presence-style environment switch once and caches the answer.
- env_
threshold_ ms - Reads a millisecond-threshold environment variable once and caches it.
Structs§
- Anchor
Id - Stable identifier for a slot in the slot table.
- Applier
Guard - A mutable applier borrow that drains recursive node disposal before returning.
- Branch
Group Guard - Callback
Holder - Callback
Holder1 - CallbackHolder1 keeps the latest single-argument callback closure alive across recompositions.
It mirrors
CallbackHolderbut supports callbacks that receive one argument. - Cancel
Token - Cooperative cancellation token passed into background
LaunchedEffectwork. - Captured
Composition Context - The composition context inherited by work that is composed in another slot host. Besides composition locals, this carries the source owner scope so a secondary tree cannot outlive the composition that supplied its callbacks.
- Composer
- Composition
- Composition
Local - Composition
Pass Debug Stats - Concrete
Applier Host - Disposable
Effect Result - Disposable
Effect Scope - Event
Handler Scope Guard - Launched
Effect Scope - Memory
Applier - Memory
Applier Debug Stats - Movable
Content - Movable content held as a value. See
rememberMovableContentOf. - Mutable
State - Cheap copyable mutable view of a state cell.
- Node
Disposal - Detached node identities and the resources that must outlive their unmount.
- Owned
Mutable State - Owning state handle for reclaimable state cells.
- Param
Slot - ParamSlot holds function/closure parameters by ownership (no PartialEq/Clone required).
Used by the
#[composable]macro to store Fn-like parameters in the slot table. - Param
State - Provided
Value - Recompose
Options - Recompose
Scope - Recompose
Scope Registry Debug Stats - Recycled
Node - Recycled
Node Insertion - Retention
Budget - Retention
Policy - Return
Slot - Slot
Debug Anchor - Slot
Debug Entry - Slot
Debug Group - Slot
Debug Scope - Slot
Debug Snapshot - Slot
Retention Debug Stats - Slot
Table - Slot
Table Debug Stats - Slot
Table Local Debug Stats - Slot
Table Mutation Debug Stats - Slots
Host - Snapshot
State List - Snapshot
State Map - State
- Cheap copyable read-only view of a state cell.
- State
Subscription Hold - Keeps a
Statecounted as subscribed while alive; seeState::subscription_hold. - Static
Composition Local - A
StaticCompositionLocalis a CompositionLocal that is optimized for values that are unlikely to change. UnlikeCompositionLocal, reads of aStaticCompositionLocalare not tracked by the recomposition system, which means: - Task
Site - Where an effect was written, carried onto the task it spawns.
- Value
Slot Handle
Enums§
Constants§
- ROOT_
RENDER_ REPLAY_ LIMIT - Upper bound on chained root-render replays and scope-recomposition rounds.
Traits§
- Applier
- Applier
Host - Owns an applier and completes node disposal when an outstanding borrow ends.
- Node
- Shared
Param - A parameter that points at a shared allocation: two that point at the same one are equal without comparing what it holds.
Functions§
- Composition
Local Provider - Disposable
Effect - Runs
effectwhen this call site first enters composition, and again wheneverkeysno longer equals the value it ran with last time; the previous run’sDisposableEffectScope::on_disposecleanup, if any, runs first, and also when the call site leaves composition entirely. - Launched
Effect - Runs
effectwhen this call site first enters composition, and again wheneverkeysno longer equals the value it ran with last time. - Launched
Effect Async - Like
LaunchedEffect, butmk_futurebuilds the future to drive rather than receiving a scope to call back into synchronously. - Side
Effect - __
disposable_ effect_ impl - __
launched_ effect_ async_ impl siteis where the effect was written. It travels onto the task the effect spawns, so a task the runtime is still holding says which effect started it.- __
launched_ effect_ impl - bubble_
layout_ dirty - Unified API for bubbling layout dirty flags from a node to the root (Applier context).
- bubble_
layout_ dirty_ in_ composer - Unified API for bubbling layout dirty flags from a node to the root (Composer context).
- bubble_
measure_ dirty - Unified API for bubbling measure dirty flags from a node to the root (Applier context).
- bubble_
measure_ dirty_ in_ composer - Unified API for bubbling measure dirty flags from a node to the root during composition.
- bubble_
semantics_ dirty - Unified API for bubbling semantics dirty flags from a node to the root (Applier context).
- bubble_
semantics_ dirty_ in_ composer - Unified API for bubbling semantics dirty flags from a node to the root (Composer context).
- composition
Local Of - composition
Local OfWith Policy - derived
State Of - A state computed from other states, as in Kotlin.
- dispatch_
ui_ event - Dispatches a UI event in a proper snapshot context.
- enter_
event_ handler_ scope - forget_
movable - Releases the state of
movablecontent with identitykeythat no parent is showing. Call it when the item is closed for good, from an event handler or inside composition. Content a parent is still showing is unaffected. Needs a runtime: an active composition or one created on this thread. - in_
applied_ snapshot - Returns true if currently in an applied snapshot context.
- in_
event_ handler - Returns true if currently in an event handler context.
- key
- Scopes composition identity to
keysfor the duration ofcontent. - location_
key - movable
- Composes
contentunder an identity that iskeyalone, the same at every call site, so the subtree can be emitted from any parent and keep its remembered values, its running effects and its nodes. - movable
Content Of - Movable content whose identity is
key, the same at every call site. - mutable
State List - mutable
State List Of - mutable
State Map - mutable
State MapOf - mutable
State Of - Creates a new
MutableStateinitialized with the given value. - mutable
State OfNever Equal - Like
mutableStateOf, for a value that cannot be compared or whose every write must count as a change. - owned
Mutable State Of - owned
Mutable State OfNever Equal - Like
ownedMutableStateOf, for a value that cannot be compared. - pop_
parent - push_
parent - queue_
semantics_ invalidation - Schedules semantics bubbling for a node using the active composer if present.
- refresh_
param - Updates one stored parameter to
newand says whether it differed, reusing the stored value’s allocations whereClone::clone_fromcan. - refresh_
shared_ param refresh_paramfor anRcorArcparameter: the same allocation is unchanged without comparing its contents, whichPartialEqon a pointer to a type that is notEqotherwise walks in full on every recomposition.- remember
- remember
Keyed - Like
remember, but recomputes wheneverkeychanges. - remember
Movable Content Of - Content written once that keeps its identity wherever it is shown.
- remember
Mutable State Of - A composable hook that creates and remembers a
MutableState. - remember
Mutable State OfNever Equal - remember
Updated State - Returns a
MutableStatethat always holds the latest value. - run_
in_ mutable_ snapshot - Runs the provided closure inside a mutable snapshot and applies the result.
- static
Composition Local Of - try_
mutable State Of - Like
mutableStateOfbut returnsNoneif no runtime is available. - with
Current Composer - with_
key - with_
node_ mut