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};
136mod scope_order;
137#[expect(clippy::multiple_inherent_impl, reason = "one file per concern")]
138mod slot;
139mod slots_host;
140pub(crate) use slots_host::SlotPassOutcome;
141pub use slots_host::SlotsHost;
142pub mod snapshot_double_index_heap;
144pub mod snapshot_id_set;
146pub mod snapshot_pinning;
148pub mod snapshot_state_observer;
150pub mod snapshot_v2;
151mod snapshot_weak_set;
152pub mod source_trace;
153mod stable_index;
154mod state;
155#[doc(hidden)]
156pub use source_trace::{__inline_source_scope, __source_scope};
157#[doc(hidden)]
158pub use thread_state::with_or_fresh;
159mod stage_times;
160pub mod subcompose;
161mod task_site;
162pub use task_site::TaskSite;
163mod thread_state;
164#[doc(hidden)]
165pub use stage_times::{StageTimes, stage_ms};
166
167#[cfg(feature = "internal")]
168#[doc(hidden)]
169pub mod internal {
170 pub use crate::{
171 frame_clock::{FrameCallbackRegistration, FrameClock},
172 node_reads::{NodeReads, ReaderGuard},
173 };
174}
175pub use applier_host::{ApplierGuard, ApplierHost, ConcreteApplierHost, NodeDisposal};
176pub use blocking::{
177 BlockingError, BlockingExecutor, BlockingExecutorConfig, BlockingTask, BlockingWork,
178 launchBlocking, withBlocking,
179};
180pub use callbacks::{
181 CallbackForwarder, CallbackHolder, ParamReturnState, ParamSlot, ParamState, ReturnSlot,
182 SharedParam, refresh_param, refresh_shared_param, store_param,
183};
184pub use composer::{
185 __branch_group_scope_advance, __branch_group_scope_deferred, BranchGroupGuard,
186 CapturedCompositionContext, ComposableGroup, Composer, ParameterChange, ScopedBranchGroupGuard,
187 ValueSlotHandle,
188};
189pub(crate) use composer::{ComposerCore, EmittedNode, ParentAttachMode, ParentFrame};
190#[cfg(any(test, feature = "leak-debug"))]
191pub use composition::CompositionPassDebugStats;
192pub use composition::{Composition, LayoutBudget, ROOT_RENDER_REPLAY_LIMIT};
193pub use composition_locals::{
194 CompositionLocal, CompositionLocalAccessorScope, CompositionLocalProvider, ProvidedValue,
195 ReadableCompositionLocal, StaticCompositionLocal, compositionLocalOf,
196 compositionLocalOfWithPolicy, compositionLocalWithComputedDefaultOf, staticCompositionLocalOf,
197 staticCompositionLocalOfWithPolicy, staticCompositionLocalWithComputedDefaultOf,
198};
199pub(crate) use composition_locals::{ComputedLocalEntry, LocalStateEntry};
200#[doc(hidden)]
201pub use computed_state::{ComputedState, computedStateOf};
202pub use concurrency::{
203 CollectEvents, CoroutineScope, Delay, EventChannel, EventSender, EventStream, EventStreamNext,
204 ProduceScope, collectAsState, delay, interval, produceState, rememberCoroutineScope,
205 rememberEventStream, spawn_ui_task,
206};
207#[doc(hidden)]
208pub use debug_trace::{
209 debug_label_current_scope, debug_live_recompose_scope_count,
210 debug_recompose_scope_registry_stats, debug_scope_invalidation_sources, debug_scope_label,
211};
212pub use hooks::{
213 derivedStateOf, mutableStateList, mutableStateListOf, mutableStateMap, mutableStateMapOf,
214 mutableStateOf, mutableStateOfNeverEqual, ownedMutableStateOf, ownedMutableStateOfNeverEqual,
215 remember, rememberKeyed, rememberMutableStateOf, rememberMutableStateOfNeverEqual,
216 rememberUpdatedState, try_mutableStateOf,
217};
218pub use launched_effect::{
219 __launched_effect_impl, CancelToken, LaunchedEffect, LaunchedEffectScope,
220};
221pub use location_key::{
222 __constant, HotOriginGuard, branch_location_key, cached_composable_definition_key,
223 caller_location_key, composable_definition_key, composable_identity_key, const_location_key,
224 constant_value_key, hot_branch_key, hot_definition_key, hot_origin, location_key,
225 noted_location_key,
226};
227pub use node_marks::NodeMarks;
228pub use owned::Owned;
229pub use platform::{Clock, RuntimeScheduler, SchedulerRef, scheduler_ref};
230pub use retention::{RetentionBudget, RetentionEvictionPolicy, RetentionMode, RetentionPolicy};
231#[doc(hidden)]
232pub use runtime::{
233 DefaultScheduler, Runtime, RuntimeHandle, StateId, TaskHandle, UiDispatcher,
234 current_runtime_handle, schedule_frame, schedule_node_update,
235};
236pub use runtime_cell::RuntimeCell;
237#[cfg(any(test, feature = "leak-debug"))]
238pub use slot::SlotTableMutationDebugStats;
239pub use slot::{
240 SlotDebugAnchor, SlotDebugEntry, SlotDebugEntryKind, SlotDebugGroup, SlotDebugScope,
241 SlotDebugSnapshot, SlotRetentionDebugStats, SlotTable, SlotTableDebugStats,
242 SlotTableLocalDebugStats,
243};
244pub use snapshot_state_observer::SnapshotStateObserver;
245pub use worker_job::{__worker, WorkerCall, WorkerData, WorkerJob};
246
247#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
250#[cfg_attr(target_os = "espidf", repr(C, packed(4)))]
251pub struct Key(pub u64);
252
253impl Key {
254 pub const fn scoped(self, site: Self) -> Self {
256 Self(self.0 ^ site.0)
257 }
258
259 pub(crate) const fn mixed(self, other: Self) -> Self {
261 Self((self.0 ^ other.0).wrapping_mul(0x0000_0100_0000_01b3))
262 }
263}
264
265impl std::fmt::Display for Key {
266 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
267 { self.0 }.fmt(f)
268 }
269}
270#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
272pub struct NodeId(pub usize);
273
274impl NodeId {
275 pub(crate) const fn next(self) -> Self {
277 Self(self.0.saturating_add(1))
278 }
279}
280
281impl std::str::FromStr for NodeId {
282 type Err = std::num::ParseIntError;
283
284 fn from_str(text: &str) -> Result<Self, Self::Err> {
285 text.parse().map(Self)
286 }
287}
288
289impl std::fmt::Display for NodeId {
290 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
291 self.0.fmt(f)
292 }
293}
294
295pub(crate) type ScopeId = usize;
296pub(crate) type FrameCallbackId = u64;
297pub use composer_context::{
298 __current_composer, note_nested_slots_host, with_composer as with_current_composer,
299};
300pub(crate) use state::MutableStateInner;
301pub use state::{
302 MutableState, OwnedMutableState, SnapshotStateList, SnapshotStateMap, State,
303 StateSubscriptionHold,
304};
305pub use subcompose::{
306 ContentTypeReusePolicy, DefaultSlotReusePolicy, SlotId, SlotReusePolicy, SubcomposeState,
307 TypedSlot,
308};
309
310#[cfg(test)]
311#[path = "tests/mod.rs"]
312mod tests;
313
314#[cfg(test)]
315#[path = "tests/recursive_decrease_increase_test.rs"]
316mod recursive_decrease_increase_test;
317
318pub mod collections;
319pub mod hash;
321
322#[cfg(any(test, feature = "test-helpers"))]
325pub mod test_scratch;
326#[cfg(any(test, feature = "test-helpers"))]
327pub use test_scratch::test_scratch_dir;