pub struct SubcomposeState { /* private fields */ }Expand description
Tracks the state of nodes produced by subcomposition, enabling reuse between measurement passes.
Implementations§
Source§impl SubcomposeState
impl SubcomposeState
Sourcepub fn new(policy: Box<dyn SlotReusePolicy>) -> Self
pub fn new(policy: Box<dyn SlotReusePolicy>) -> Self
Creates a new SubcomposeState using the supplied reuse policy.
Sourcepub fn set_policy(&mut self, policy: Box<dyn SlotReusePolicy>)
pub fn set_policy(&mut self, policy: Box<dyn SlotReusePolicy>)
Sets the policy used for future reuse decisions.
Sourcepub fn register_content_type(&mut self, slot_id: SlotId, content_type: u64)
pub fn register_content_type(&mut self, slot_id: SlotId, content_type: u64)
Registers a content type for a slot.
Stores the content type locally for efficient pool-based reuse lookup, and also delegates to the policy for compatibility checking.
Call this before subcomposing an item to enable content-type-aware slot reuse.
Sourcepub fn update_content_type(
&mut self,
slot_id: SlotId,
content_type: Option<u64>,
)
pub fn update_content_type( &mut self, slot_id: SlotId, content_type: Option<u64>, )
Updates the content type for a slot, handling Some→None transitions.
If content_type is Some(type), registers the type for the slot.
If content_type is None, removes any previously registered type.
This ensures stale types don’t drive incorrect reuse.
Sourcepub fn get_content_type(&self, slot_id: SlotId) -> Option<u64>
pub fn get_content_type(&self, slot_id: SlotId) -> Option<u64>
Returns the content type for a slot, if registered.
Sourcepub fn begin_pass(&mut self)
pub fn begin_pass(&mut self)
Starts a new subcompose pass.
Call this before subcomposing the current frame so the state can track which slots are active and dispose the inactive ones later.
Sourcepub fn finish_pass(&mut self) -> Vec<NodeId> ⓘ
pub fn finish_pass(&mut self) -> Vec<NodeId> ⓘ
Finishes a subcompose pass, disposing slots that were not used.
Sourcepub fn get_or_create_slots(&mut self, slot_id: SlotId) -> Rc<SlotsHost>
pub fn get_or_create_slots(&mut self, slot_id: SlotId) -> Rc<SlotsHost>
Returns the SlotsHost for the given slot ID, creating a new one if it doesn’t exist. Each slot gets its own isolated slot table, avoiding cursor-based conflicts when items are subcomposed in different orders.
Sourcepub fn register_active(
&mut self,
slot_id: SlotId,
node_ids: &[NodeId],
scopes: &[RecomposeScope],
)
pub fn register_active( &mut self, slot_id: SlotId, node_ids: &[NodeId], scopes: &[RecomposeScope], )
Records that the nodes in node_ids are currently rendering the provided
slot_id.
Sourcepub fn register_precomposed(&mut self, slot_id: SlotId, node_id: NodeId)
pub fn register_precomposed(&mut self, slot_id: SlotId, node_id: NodeId)
Stores a precomposed node for the provided slot. Precomposed nodes stay
detached from the tree until they are activated by register_active.
Sourcepub fn take_node_from_reusables(&mut self, slot_id: SlotId) -> Option<NodeId>
pub fn take_node_from_reusables(&mut self, slot_id: SlotId) -> Option<NodeId>
Returns the node that previously rendered this slot, if it is still considered reusable. Uses O(1) content-type based lookup when available.
Lookup order:
- Exact slot match in the appropriate pool
- Any compatible node from the same content-type pool (O(1) pop)
- Fallback to untyped pool with policy compatibility check
Sourcepub fn dispose_or_reuse_starting_from_index(
&mut self,
start_index: usize,
) -> Vec<NodeId> ⓘ
pub fn dispose_or_reuse_starting_from_index( &mut self, start_index: usize, ) -> Vec<NodeId> ⓘ
Moves active slots starting from start_index to the reusable bucket.
Returns the list of node ids that were DISPOSED (not just moved to reusable).
Nodes that exceed max_reusable_per_type are disposed instead of cached.
Sourcepub fn active_slots_count(&self) -> usize
pub fn active_slots_count(&self) -> usize
Returns the number of slots currently active (in use during this pass).
This reflects the slots that were activated via register_active() during
the current measurement pass.
Sourcepub fn reusable_slots_count(&self) -> usize
pub fn reusable_slots_count(&self) -> usize
Returns the number of reusable slots in the pool.
These are slots that were previously active but are now available for reuse by compatible content types.
Sourcepub fn was_last_slot_reused(&self) -> Option<bool>
pub fn was_last_slot_reused(&self) -> Option<bool>
Returns whether the last slot registered via [register_active] was reused.
Returns Some(true) if the slot already existed (was reused from pool or
was recomposed), Some(false) if it was newly created, or None if no
slot has been registered yet this pass.
This is useful for tracking composition statistics in lazy layouts.
Sourcepub fn precomposed(&self) -> &HashMap<SlotId, Vec<NodeId>>
pub fn precomposed(&self) -> &HashMap<SlotId, Vec<NodeId>>
Returns a snapshot of precomposed nodes.
Sourcepub fn drain_inactive_precomposed(&mut self) -> Vec<NodeId> ⓘ
pub fn drain_inactive_precomposed(&mut self) -> Vec<NodeId> ⓘ
Removes any precomposed nodes whose slots were not activated during the current pass and returns their identifiers for disposal.