ferroui_base/rendering/composition/i_compositor_serializable.rs
1use super::server::ServerObjectId;
2use super::transport::BatchStreamWriter;
3use super::Compositor;
4
5/// An object whose changes are serialized into the next batch of a
6/// compositor.
7pub trait ICompositorSerializable {
8 /// The server-side counterpart of the object on compositor `c`, if it
9 /// has one.
10 fn try_get_server(&self, c: &Compositor) -> Option<ServerObjectId>;
11
12 /// The identity of the object, by which a compositor avoids queueing
13 /// it twice. The default is the address of the implementing value; an
14 /// adapter around an object returns the identity of that object.
15 fn serialization_key(&self) -> *const () {
16 self as *const Self as *const ()
17 }
18
19 /// Called before the changes of the object are written for compositor
20 /// `c`.
21 ///
22 /// A server object is referred to by its id and created by the batch
23 /// itself, so an object whose changes refer to server objects that only
24 /// come to exist while it is serialized (the recorded content of a
25 /// scene brush) creates them here: their creation is then written
26 /// before the changes that refer to them.
27 fn prepare_serialization(&self, _c: &Compositor) {}
28
29 /// Writes the pending changes of the object for compositor `c`.
30 fn serialize_changes(&self, c: &Compositor, writer: &mut BatchStreamWriter<'_>);
31}