pub struct Composition<A: Applier + 'static> { /* private fields */ }Expand description
A running composition that turns root content into nodes. A is the applier type that creates
and edits those nodes.
Implementations§
Source§impl<A: Applier + 'static> Composition<A>
impl<A: Applier + 'static> Composition<A>
Sourcepub fn new(applier: A) -> Self
pub fn new(applier: A) -> Self
Creates a composition that builds its nodes through applier and uses a new runtime with
the default scheduler.
Sourcepub fn with_runtime(applier: A, runtime: Runtime) -> Self
pub fn with_runtime(applier: A, runtime: Runtime) -> Self
Creates a composition that builds its nodes through applier and uses runtime for state
invalidation and scheduling.
Sourcepub fn root_key(&self) -> Option<Key>
pub fn root_key(&self) -> Option<Key>
Returns the root group key captured from the most recent render() call,
or None before the first render.
Sourcepub fn set_retention_policy(&self, policy: RetentionPolicy)
pub fn set_retention_policy(&self, policy: RetentionPolicy)
Sets the budget and the eviction order for groups retained when they leave the composition.
See RetentionMode.
Sourcepub fn take_root_render_request(&mut self) -> bool
pub fn take_root_render_request(&mut self) -> bool
Returns whether a root render was requested and clears the request.
Sourcepub fn request_root_render(&mut self)
pub fn request_root_render(&mut self)
Requests another render of the root content and schedules a frame for it.
Sourcepub fn render(
&mut self,
key: Key,
content: impl FnMut(),
) -> Result<(), NodeError>
pub fn render( &mut self, key: Key, content: impl FnMut(), ) -> Result<(), NodeError>
Composes content as the root group identified by key, then recomposes the scopes that
became invalid during the pass.
Sourcepub fn render_stable(
&mut self,
key: Key,
content: impl FnMut(),
) -> Result<(), NodeError>
pub fn render_stable( &mut self, key: Key, content: impl FnMut(), ) -> Result<(), NodeError>
Perform a root render and continue replaying any resulting root-render requests until the composition reaches a stable fixpoint.
Sourcepub fn reconcile(
&mut self,
key: Key,
content: impl FnMut(),
) -> Result<bool, NodeError>
pub fn reconcile( &mut self, key: Key, content: impl FnMut(), ) -> Result<bool, NodeError>
Process invalid scopes and any resulting root-render requests until the composition reaches a stable fixpoint for the supplied root content.
Sourcepub fn should_render(&self) -> bool
pub fn should_render(&self) -> bool
Returns true if composition needs to process invalid scopes (recompose).
This checks both:
has_updates(): composition scopes that were invalidated by state changesneeds_frame(): animation callbacks that may have pending work
Note: For scroll performance, ensure scroll state changes use Cell<T> instead
of MutableState<T> to avoid triggering recomposition on every scroll frame.
Sourcepub fn should_recompose(&self) -> bool
pub fn should_recompose(&self) -> bool
Whether any composition scope is actually invalid, i.e. whether running the composable tree could produce a different result than last time.
Deliberately excludes Runtime::needs_frame, which Self::should_render
includes. An armed frame callback means the runtime owes someone a
tick - a future to resume, a dispatcher to drain - and every app with a
game loop or a polling effect has one armed at all times. Re-running the
composition for it recomposes a tree that nothing invalidated. Callers
deciding “should I tick” want Self::should_render; callers deciding
“should I recompose” want this.
It is only meaningful after the frame callbacks have been drained: a callback that writes state invalidates its readers as it runs, so the answer is a question about work already discovered, not work still to come.
Sourcepub fn runtime_handle(&self) -> RuntimeHandle
pub fn runtime_handle(&self) -> RuntimeHandle
Returns a handle to the runtime this composition uses.
Sourcepub fn applier_mut(&mut self) -> ApplierGuard<'_, A>
pub fn applier_mut(&mut self) -> ApplierGuard<'_, A>
Borrows the applier mutably. Panics if it is already borrowed.
Sourcepub fn root(&self) -> Option<NodeId>
pub fn root(&self) -> Option<NodeId>
Returns the root node a pass produced, or None if none has yet.
Sourcepub fn debug_dump_slot_table_groups(
&self,
) -> Vec<(usize, Key, Option<usize>, usize)>
pub fn debug_dump_slot_table_groups( &self, ) -> Vec<(usize, Key, Option<usize>, usize)>
Returns one (group index, call site key, scope id, subtree length) tuple per group in the
slot table, for debugging.
Sourcepub fn debug_dump_slot_entries(&self) -> Vec<SlotDebugEntry>
pub fn debug_dump_slot_entries(&self) -> Vec<SlotDebugEntry>
Returns the entries of the slot table, for debugging.
Sourcepub fn slot_table_heap_bytes(&self) -> usize
pub fn slot_table_heap_bytes(&self) -> usize
Returns the heap memory in bytes that the slot table holds.
Sourcepub fn debug_slot_table_stats(&self) -> SlotTableDebugStats
pub fn debug_slot_table_stats(&self) -> SlotTableDebugStats
Returns size counters of the slot table, for debugging.
Sourcepub fn debug_slot_snapshot(&self) -> SlotDebugSnapshot
pub fn debug_slot_snapshot(&self) -> SlotDebugSnapshot
Returns a copy of the slot table’s structure, for debugging.
Sourcepub fn debug_last_pass_stats(&self) -> CompositionPassDebugStats
pub fn debug_last_pass_stats(&self) -> CompositionPassDebugStats
Returns the buffer sizes of the last composition pass, for debugging.
Sourcepub fn process_invalid_scopes(&mut self) -> Result<bool, NodeError>
pub fn process_invalid_scopes(&mut self) -> Result<bool, NodeError>
Recomposes the scopes that state changes invalidated, until none remain or a root render is
requested. Returns true if a pass recomposed content.
Source§impl<A: Applier + 'static> Composition<A>
impl<A: Applier + 'static> Composition<A>
Sourcepub fn flush_pending_node_updates(&mut self) -> Result<(), NodeError>
pub fn flush_pending_node_updates(&mut self) -> Result<(), NodeError>
Applies the node updates that the runtime has queued to the applier, without recomposing.