1#![deny(missing_docs)]
2#![doc = include_str!("../README.md")]
3#![deny(unsafe_code)]
4
5pub extern crate self as cranpose_core;
6
7mod applier;
8mod applier_host;
9pub use applier::Applier;
10mod blocking;
11mod bubble_passes;
12mod callbacks;
13mod child_positions;
14mod child_sync;
15pub(crate) use child_positions::{
16 build_child_positions, insert_child_into_diff_state, move_child_in_diff_state,
17};
18pub(crate) use child_sync::{
19 apply_remove_child, attach_child_at, cleanup_detached_child, detach_child_from_parent,
20 insert_child_with_reparenting, join_made_children, remove_child_and_cleanup_now,
21 sync_or_settle_children,
22};
23mod command;
24pub(crate) use command::{
25 Command, CommandCallback, DeferredChildCleanup, DeferredChildCleanupQueue, DirtyBubble,
26};
27mod command_queue;
28pub(crate) use command_queue::{
29 COMMAND_FLUSH_THRESHOLD, ChildList, CommandQueue, SMALL_CHILD_SYNC_LINEAR_THRESHOLD,
30};
31#[cfg(test)]
32pub(crate) use command_queue::{CommandTag, SyncChildrenCommand};
33mod composer;
34pub mod composer_context;
37pub(crate) use composer_context::with_current_composer_opt;
38pub use composer_context::{
39 current_recompose_scope_invalidated_only_by, recompose_current_scope_again, withCurrentComposer,
40};
41mod composition;
42mod composition_locals;
43pub(crate) use composition_locals::{LocalKey, LocalStackSnapshot};
44mod computed_state;
45pub mod concurrency;
46mod debug_trace;
47mod disposable_effect;
48pub use diagnostics::{DIAGNOSTICS, Diagnostic, Diagnostics};
49#[cfg(test)]
50pub(crate) use disposable_effect::DisposableEffectState;
51pub use disposable_effect::{
52 __disposable_effect_impl, DisposableEffect, DisposableEffectResult, DisposableEffectScope,
53 SideEffect,
54};
55mod effect_key;
56mod emit;
57mod event_dispatch;
58pub use event_dispatch::{
59 EventHandlerScopeGuard, dispatch_ui_event, enter_event_handler_scope, in_applied_snapshot,
60 in_event_handler, run_in_mutable_snapshot,
61};
62pub mod debug_toggles;
63pub mod diagnostics;
64#[cfg(any(feature = "internal", test))]
65mod frame_clock;
66mod hooks;
67#[cfg(feature = "internal")]
68mod node_reads;
69pub(crate) use key_group::{explicit_group_key_seed, hash_key};
70mod key_group;
71pub use key_group::{key, with_key};
72mod launched_effect;
73mod layout_dirt_roots;
74mod location_key;
75mod memory_applier;
76mod worker_job;
77#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
78mod worker_pool;
79pub use memory_applier::{MemoryApplier, MemoryApplierDebugStats, SceneNodeAttachmentScratch};
80mod movable_content;
81mod node;
82#[cfg(any(test, debug_assertions))]
83pub(crate) use location_key::LocationKeyDebugInfo;
84pub(crate) use location_key::{HotOrigin, avalanche_location_key};
85#[cfg(test)]
86pub(crate) use location_key::{
87 hot_call_site_key, location_key_debug_collision_count_for_test,
88 location_key_debug_info_for_test, register_location_key_debug_info_for_test,
89};
90pub use movable_content::{
91 MovableContent, forget_movable, movable, movableContentOf, rememberMovableContentOf,
92};
93pub use node::{
94 Node, bubble_layout_dirty, bubble_layout_dirty_in_composer, bubble_measure_dirty,
95 bubble_measure_dirty_in_composer, bubble_semantics_dirty, bubble_semantics_dirty_in_composer,
96 pop_parent, push_parent, queue_semantics_invalidation, with_node_mut,
97};
98mod node_error;
99mod node_id_cell;
100pub use node_id_cell::NodeIdCell;
101mod packed_node_id;
102pub use packed_node_id::PackedNodeId;
103mod node_marks;
104mod phase;
105pub use phase::Phase;
106mod anchor_id;
107pub use anchor_id::AnchorId;
108mod packed_u64;
109pub use node_error::NodeError;
110pub use packed_u64::PackedU64;
111mod process_ids;
112pub use process_ids::ProcessIds;
113pub mod owned;
115mod pausable;
116#[doc(hidden)]
117pub use pausable::{PausableContent, with_pausable_content};
118pub mod platform;
119mod recompose;
120mod recompose_scope;
121pub(crate) use recompose_scope::{BodyRun, RecomposeScopeInner, ScopeRead};
122pub use recompose_scope::{RecomposeOptions, RecomposeScope, RecomposeScopeRegistryDebugStats};
123mod recycle_pool;
124mod recycled_node;
125use recycle_pool::RecyclePool;
126pub use recycled_node::{RecycleOrigin, RecycledNode, RecycledNodeInsertion};
127mod retention;
128pub mod runtime;
131mod runtime_cell;
132#[cfg(test)]
133pub(crate) use runtime::{TestRuntime, TestScheduler};
134mod scene_records;
135pub use scene_records::{RecordId, RecordRef, SceneUpdate, StoreId};
136#[expect(clippy::multiple_inherent_impl, reason = "one file per concern")]
137mod slot;
138mod slots_host;
139pub(crate) use slots_host::SlotPassOutcome;
140pub use slots_host::SlotsHost;
141pub mod snapshot_double_index_heap;
143pub mod snapshot_id_set;
145pub mod snapshot_pinning;
147pub mod snapshot_state_observer;
149pub mod snapshot_v2;
150mod snapshot_weak_set;
151pub mod source_trace;
152mod stable_index;
153mod state;
154#[doc(hidden)]
155pub use source_trace::{__inline_source_scope, __source_scope};
156#[doc(hidden)]
157pub use thread_state::with_or_fresh;
158mod stage_times;
159pub mod subcompose;
160mod task_site;
161pub use task_site::TaskSite;
162mod thread_state;
163#[doc(hidden)]
164pub use stage_times::{StageTimes, stage_ms};
165
166#[cfg(feature = "internal")]
167#[doc(hidden)]
168pub mod internal {
169 pub use crate::{
170 frame_clock::{FrameCallbackRegistration, FrameClock},
171 node_reads::{NodeReads, ReaderGuard},
172 };
173}
174pub use applier_host::{ApplierGuard, ApplierHost, ConcreteApplierHost, NodeDisposal};
175pub use blocking::{
176 BlockingError, BlockingExecutor, BlockingExecutorConfig, BlockingTask, BlockingWork,
177 launchBlocking, withBlocking,
178};
179pub use callbacks::{
180 CallbackForwarder, CallbackHolder, ParamReturnState, ParamSlot, ParamState, ReturnSlot,
181 SharedParam, refresh_param, refresh_shared_param, store_param,
182};
183pub use composer::{
184 __branch_group_scope_advance, __branch_group_scope_deferred, BranchGroupGuard,
185 CapturedCompositionContext, ComposableGroup, Composer, ParameterChange, ScopedBranchGroupGuard,
186 ValueSlotHandle,
187};
188pub(crate) use composer::{ComposerCore, EmittedNode, ParentAttachMode, ParentFrame};
189#[cfg(any(test, feature = "leak-debug"))]
190pub use composition::CompositionPassDebugStats;
191pub use composition::{Composition, LayoutBudget, ROOT_RENDER_REPLAY_LIMIT};
192pub use composition_locals::{
193 CompositionLocal, CompositionLocalAccessorScope, CompositionLocalProvider, ProvidedValue,
194 ReadableCompositionLocal, StaticCompositionLocal, compositionLocalOf,
195 compositionLocalOfWithPolicy, compositionLocalWithComputedDefaultOf, staticCompositionLocalOf,
196 staticCompositionLocalOfWithPolicy, staticCompositionLocalWithComputedDefaultOf,
197};
198pub(crate) use composition_locals::{ComputedLocalEntry, LocalStateEntry};
199#[doc(hidden)]
200pub use computed_state::{ComputedState, computedStateOf};
201pub use concurrency::{
202 CollectEvents, CoroutineScope, Delay, EventChannel, EventSender, EventStream, EventStreamNext,
203 ProduceScope, collectAsState, delay, interval, produceState, rememberCoroutineScope,
204 rememberEventStream, spawn_ui_task,
205};
206#[doc(hidden)]
207pub use debug_trace::{
208 debug_label_current_scope, debug_live_recompose_scope_count,
209 debug_recompose_scope_registry_stats, debug_scope_invalidation_sources, debug_scope_label,
210};
211pub use hooks::{
212 derivedStateOf, mutableStateList, mutableStateListOf, mutableStateMap, mutableStateMapOf,
213 mutableStateOf, mutableStateOfNeverEqual, ownedMutableStateOf, ownedMutableStateOfNeverEqual,
214 remember, rememberKeyed, rememberMutableStateOf, rememberMutableStateOfNeverEqual,
215 rememberUpdatedState, try_mutableStateOf,
216};
217pub use launched_effect::{
218 __launched_effect_impl, CancelToken, LaunchedEffect, LaunchedEffectScope,
219};
220pub use location_key::{
221 __constant, HotOriginGuard, branch_location_key, cached_composable_definition_key,
222 caller_location_key, composable_definition_key, composable_identity_key, const_location_key,
223 constant_value_key, hot_branch_key, hot_definition_key, hot_origin, location_key,
224 noted_location_key,
225};
226pub use node_marks::NodeMarks;
227pub use owned::Owned;
228pub use platform::{Clock, RuntimeScheduler, SchedulerRef, scheduler_ref};
229pub use retention::{RetentionBudget, RetentionEvictionPolicy, RetentionMode, RetentionPolicy};
230#[doc(hidden)]
231pub use runtime::{
232 DefaultScheduler, Runtime, RuntimeHandle, StateId, TaskHandle, UiDispatcher,
233 current_runtime_handle, schedule_frame, schedule_node_update,
234};
235pub use runtime_cell::RuntimeCell;
236#[cfg(any(test, feature = "leak-debug"))]
237pub use slot::SlotTableMutationDebugStats;
238pub use slot::{
239 SlotDebugAnchor, SlotDebugEntry, SlotDebugEntryKind, SlotDebugGroup, SlotDebugScope,
240 SlotDebugSnapshot, SlotRetentionDebugStats, SlotTable, SlotTableDebugStats,
241 SlotTableLocalDebugStats,
242};
243pub use snapshot_state_observer::SnapshotStateObserver;
244pub use worker_job::{__worker, WorkerCall, WorkerData, WorkerJob};
245
246#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
249#[cfg_attr(target_os = "espidf", repr(C, packed(4)))]
250pub struct Key(pub u64);
251
252impl Key {
253 pub const fn scoped(self, site: Self) -> Self {
255 Self(self.0 ^ site.0)
256 }
257
258 pub(crate) const fn mixed(self, other: Self) -> Self {
260 Self((self.0 ^ other.0).wrapping_mul(0x0000_0100_0000_01b3))
261 }
262}
263
264impl std::fmt::Display for Key {
265 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
266 { self.0 }.fmt(f)
267 }
268}
269#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
271pub struct NodeId(pub usize);
272
273impl NodeId {
274 pub(crate) const fn next(self) -> Self {
276 Self(self.0.saturating_add(1))
277 }
278}
279
280impl std::str::FromStr for NodeId {
281 type Err = std::num::ParseIntError;
282
283 fn from_str(text: &str) -> Result<Self, Self::Err> {
284 text.parse().map(Self)
285 }
286}
287
288impl std::fmt::Display for NodeId {
289 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
290 self.0.fmt(f)
291 }
292}
293
294pub(crate) type ScopeId = usize;
295pub(crate) type FrameCallbackId = u64;
296pub use composer_context::{
297 __current_composer, note_nested_slots_host, with_composer as with_current_composer,
298};
299pub(crate) use state::MutableStateInner;
300pub use state::{
301 MutableState, OwnedMutableState, SnapshotStateList, SnapshotStateMap, State,
302 StateSubscriptionHold,
303};
304pub use subcompose::{
305 ContentTypeReusePolicy, DefaultSlotReusePolicy, SlotId, SlotReusePolicy, SubcomposeState,
306 TypedSlot,
307};
308
309#[cfg(test)]
310#[path = "tests/mod.rs"]
311mod tests;
312
313#[cfg(test)]
314#[path = "tests/recursive_decrease_increase_test.rs"]
315mod recursive_decrease_increase_test;
316
317pub mod collections;
318pub mod hash;
320
321#[cfg(any(test, feature = "test-helpers"))]
324pub mod test_scratch;
325#[cfg(any(test, feature = "test-helpers"))]
326pub use test_scratch::test_scratch_dir;