pub struct Batch { /* private fields */ }Expand description
One batch, written by the runtime and by the Host into the same arena.
The Host opens it with Batch::begin, writes the records that are its own (the theme,
the window, assets, messages, notifications, streamed tails) and has the runtime write
the tree’s records between them, then closes it with Batch::finish. The bytes that
come back are what the boundary hands the Renderer.
A runtime has no fallible way to report a bad record from the middle of a diff, so
Batch::fail keeps the error and finish returns it in place of the batch.
Implementations§
Source§impl Batch
impl Batch
Sourcepub fn new() -> Self
pub fn new() -> Self
Sized so that an ordinary screen’s batches never grow it: once warm, writing a frame allocates nothing.
Sourcepub fn arena(&self) -> (*const u8, usize)
pub fn arena(&self) -> (*const u8, usize)
The batch arena, so a Renderer that reads Host memory through a mapped view can be handed one.
Sourcepub fn begin(&mut self)
pub fn begin(&mut self)
Starts a new batch, discarding the previous one and any error it carried.
Sourcepub fn finish(&mut self) -> Result<&[u8], ProtocolError>
pub fn finish(&mut self) -> Result<&[u8], ProtocolError>
Closes the batch and returns its bytes, or the first error written into it.
Sourcepub fn write(&mut self, mutation: Mutation<'_>)
pub fn write(&mut self, mutation: Mutation<'_>)
Writes one record. After an error nothing more is written: the batch is already going to be refused.
Sourcepub fn fail(&mut self, error: ProtocolError)
pub fn fail(&mut self, error: ProtocolError)
Records an error found while building the batch. finish returns it.
Sourcepub fn set_theme(&mut self, theme: Theme)
pub fn set_theme(&mut self, theme: Theme)
The root theme record. Written once per rebuild, never per frame.
Sourcepub fn set_window(&mut self, window: Window)
pub fn set_window(&mut self, window: Window)
The root window record. Written once per rebuild, never per frame.
pub fn set_text_node( &mut self, node_id: u32, text: &str, selection: Option<Selection>, )
Sourcepub fn register_asset(&mut self, asset_id: u32, kind: AssetKind, bytes: &[u8])
pub fn register_asset(&mut self, asset_id: u32, kind: AssetKind, bytes: &[u8])
Copies one asset into the batch. The bytes ride behind the records, and the Renderer takes its own copy inside the call that carries them.
pub fn release_asset(&mut self, asset_id: u32)
Sourcepub fn show_message(
&mut self,
handler_id: u64,
text: &str,
action: &str,
duration: MessageDuration,
)
pub fn show_message( &mut self, handler_id: u64, text: &str, action: &str, duration: MessageDuration, )
Writes one transient message into the batch.
It names no node, because a message is not in the tree: it is a sentence with a lifetime, and that lifetime belongs to the Renderer.
Sourcepub fn append_text_node(&mut self, node_id: u32, text: &str)
pub fn append_text_node(&mut self, node_id: u32, text: &str)
Appends the streamed tail to a Text node without resending its whole value.