pub trait SlotReusePolicy: 'static {
// Required methods
fn get_slots_to_retain(&self, active: &[SlotId]) -> HashSet<SlotId>;
fn are_compatible(&self, existing: SlotId, requested: SlotId) -> bool;
// Provided methods
fn register_content_type(&self, _slot_id: SlotId, _content_type: u64) { ... }
fn remove_content_type(&self, _slot_id: SlotId) { ... }
fn prune_slots(&self, _keep_slots: &HashSet<SlotId>) { ... }
}Expand description
Policy that decides which previously composed slots should be retained for potential reuse during the next subcompose pass.
Note: This trait does NOT require Send + Sync because the compose runtime is single-threaded (uses Rc/RefCell throughout).
Required Methods§
Sourcefn get_slots_to_retain(&self, active: &[SlotId]) -> HashSet<SlotId>
fn get_slots_to_retain(&self, active: &[SlotId]) -> HashSet<SlotId>
Returns the subset of slots that should be retained for reuse after the current measurement pass. Slots that are not part of the returned set will be disposed.
Sourcefn are_compatible(&self, existing: SlotId, requested: SlotId) -> bool
fn are_compatible(&self, existing: SlotId, requested: SlotId) -> bool
Determines whether a node that previously rendered the slot existing
can be reused when the caller requests requested.
Implementations should document what constitutes compatibility (for
example, identical slot identifiers, matching layout classes, or node
types). Returning true allows SubcomposeState to migrate the node
across slots instead of disposing it.
Provided Methods§
Sourcefn register_content_type(&self, _slot_id: SlotId, _content_type: u64)
fn register_content_type(&self, _slot_id: SlotId, _content_type: u64)
Registers the content type for a slot.
Policies that support content-type-based reuse (like ContentTypeReusePolicy)
should override this to record the type. The default implementation is a no-op.
Call this before subcomposing an item to enable content-type-aware slot reuse.
Sourcefn remove_content_type(&self, _slot_id: SlotId)
fn remove_content_type(&self, _slot_id: SlotId)
Removes the content type for a slot (e.g., when transitioning to None).
Policies that track content types should override this to clean up. The default implementation is a no-op.
Sourcefn prune_slots(&self, _keep_slots: &HashSet<SlotId>)
fn prune_slots(&self, _keep_slots: &HashSet<SlotId>)
Prunes slot data for slots not in the active set.
Called during SubcomposeState::prune_inactive_slots to allow policies
to clean up any internal state for slots that are no longer needed.
The default implementation is a no-op.