Skip to main content

SlotReusePolicy

Trait SlotReusePolicy 

Source
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) { ... }
}
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§

Source

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.

Source

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 move the node across slots instead of disposing it.

Provided Methods§

Source

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.

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§