Skip to main content

Crate cranpose_core

Crate cranpose_core 

Source
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-helpers so 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§

AnchorId
Stable identifier for a slot in the slot table.
ApplierGuard
A mutable applier borrow that drains recursive node disposal before returning.
BranchGroupGuard
CallbackHolder
CallbackHolder1
CallbackHolder1 keeps the latest single-argument callback closure alive across recompositions. It mirrors CallbackHolder but supports callbacks that receive one argument.
CancelToken
Cooperative cancellation token passed into background LaunchedEffect work.
CapturedCompositionContext
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
CompositionLocal
CompositionPassDebugStats
ConcreteApplierHost
DisposableEffectResult
DisposableEffectScope
EventHandlerScopeGuard
LaunchedEffectScope
MemoryApplier
MemoryApplierDebugStats
MovableContent
Movable content held as a value. See rememberMovableContentOf.
MutableState
Cheap copyable mutable view of a state cell.
NodeDisposal
Detached node identities and the resources that must outlive their unmount.
OwnedMutableState
Owning state handle for reclaimable state cells.
ParamSlot
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.
ParamState
ProvidedValue
RecomposeOptions
RecomposeScope
RecomposeScopeRegistryDebugStats
RecycledNode
RecycledNodeInsertion
RetentionBudget
RetentionPolicy
ReturnSlot
SlotDebugAnchor
SlotDebugEntry
SlotDebugGroup
SlotDebugScope
SlotDebugSnapshot
SlotRetentionDebugStats
SlotTable
SlotTableDebugStats
SlotTableLocalDebugStats
SlotTableMutationDebugStats
SlotsHost
SnapshotStateList
SnapshotStateMap
State
Cheap copyable read-only view of a state cell.
StateSubscriptionHold
Keeps a State counted as subscribed while alive; see State::subscription_hold.
StaticCompositionLocal
A StaticCompositionLocal is a CompositionLocal that is optimized for values that are unlikely to change. Unlike CompositionLocal, reads of a StaticCompositionLocal are not tracked by the recomposition system, which means:
TaskSite
Where an effect was written, carried onto the task it spawns.
ValueSlotHandle

Enums§

NodeError
Phase
RetentionEvictionPolicy
RetentionMode
SlotDebugEntryKind

Constants§

ROOT_RENDER_REPLAY_LIMIT
Upper bound on chained root-render replays and scope-recomposition rounds.

Traits§

Applier
ApplierHost
Owns an applier and completes node disposal when an outstanding borrow ends.
Node
SharedParam
A parameter that points at a shared allocation: two that point at the same one are equal without comparing what it holds.

Functions§

CompositionLocalProvider
DisposableEffect
Runs effect when this call site first enters composition, and again whenever keys no longer equals the value it ran with last time; the previous run’s DisposableEffectScope::on_dispose cleanup, if any, runs first, and also when the call site leaves composition entirely.
LaunchedEffect
Runs effect when this call site first enters composition, and again whenever keys no longer equals the value it ran with last time.
LaunchedEffectAsync
Like LaunchedEffect, but mk_future builds the future to drive rather than receiving a scope to call back into synchronously.
SideEffect
__disposable_effect_impl
__launched_effect_async_impl
site is 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).
compositionLocalOf
compositionLocalOfWithPolicy
derivedStateOf
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 movable content with identity key that 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 keys for the duration of content.
location_key
movable
Composes content under an identity that is key alone, 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.
movableContentOf
Movable content whose identity is key, the same at every call site.
mutableStateList
mutableStateListOf
mutableStateMap
mutableStateMapOf
mutableStateOf
Creates a new MutableState initialized with the given value.
mutableStateOfNeverEqual
Like mutableStateOf, for a value that cannot be compared or whose every write must count as a change.
ownedMutableStateOf
ownedMutableStateOfNeverEqual
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 new and says whether it differed, reusing the stored value’s allocations where Clone::clone_from can.
refresh_shared_param
refresh_param for an Rc or Arc parameter: the same allocation is unchanged without comparing its contents, which PartialEq on a pointer to a type that is not Eq otherwise walks in full on every recomposition.
remember
rememberKeyed
Like remember, but recomputes whenever key changes.
rememberMovableContentOf
Content written once that keeps its identity wherever it is shown.
rememberMutableStateOf
A composable hook that creates and remembers a MutableState.
rememberMutableStateOfNeverEqual
rememberUpdatedState
Returns a MutableState that always holds the latest value.
run_in_mutable_snapshot
Runs the provided closure inside a mutable snapshot and applies the result.
staticCompositionLocalOf
try_mutableStateOf
Like mutableStateOf but returns None if no runtime is available.
withCurrentComposer
with_key
with_node_mut

Type Aliases§

Key
NodeId