Trait smithay::wayland::compositor::Cacheable[][src]

pub trait Cacheable: Default {
    fn commit(&mut self) -> Self;
fn merge_into(self, into: &mut Self); }
Expand description

Trait representing a value that can be used in double-buffered storage

The type needs to implement the Default trait, which will be used to initialize. You further need to provide two methods: Cacheable::commit and Cacheable::merge_into.

Double-buffered state works by having a “pending” instance of your type, into which new values provided by the client are inserted. When the client sends wl_surface.commit, the Cacheable::commit method will be invoked on your value. This method is expected to produce a new instance of your type, that will be stored in the cache, and eventually merged into the current state.

In most cases, this method will simply produce a copy of the pending state, but you might need additional logic in some cases, such as for handling non-cloneable resources (which thus need to be moved into the produce value).

Then at some point the Cacheable::merge_into method of your type will be invoked. In this method, self acts as the update that should be merged into the current state provided as argument. In simple cases, the action would just be to copy self into the current state, but more complex cases require additional logic.

Required methods

Produce a new state to be cached from the pending state

Merge a state update into the current state

Implementors