pub trait Runtime {
// Required methods
fn batch(&self) -> &Batch;
fn batch_mut(&mut self) -> &mut Batch;
fn rebuild(&mut self);
fn render(&mut self);
fn handle_event(
&mut self,
event: &HostEvent<'_>,
) -> Result<i64, ProtocolError>;
// Provided methods
fn size_token(&self, node_id: u32) -> Option<u32> { ... }
fn poll_work(&mut self, context: &mut Context<'_>) -> Poll<()> { ... }
fn run_in_context(&mut self, action: &mut dyn FnMut()) { ... }
}Expand description
What builds and changes the tree, seen from the boundary.
The Host owns everything that is not the tree and calls in here for the rest. Every
method runs on the Renderer’s UI thread, inside a boundary call, between a
Batch::begin and a Batch::finish the Host makes on Runtime::batch_mut, so a
runtime writes its records and returns; it never opens or closes a batch itself.
Required Methods§
Sourcefn batch(&self) -> &Batch
fn batch(&self) -> &Batch
The batch this runtime writes the tree’s records into. The Host writes its own records into the same one, before and after the runtime’s.
fn batch_mut(&mut self) -> &mut Batch
Sourcefn rebuild(&mut self)
fn rebuild(&mut self)
Writes the whole tree. Called once on a fresh runtime, which is also what a resync gets: the Host makes a new runtime and rebuilds it.
Sourcefn render(&mut self)
fn render(&mut self)
Writes whatever changed since the last call: state a worker wrote, a scope that a size class or a design system woke, the consequences of an event.
Sourcefn handle_event(&mut self, event: &HostEvent<'_>) -> Result<i64, ProtocolError>
fn handle_event(&mut self, event: &HostEvent<'_>) -> Result<i64, ProtocolError>
Runs the handler an event names, and nothing else: the Host renders afterwards.
Returns the value the boundary hands back as the call’s result, which is how a key handler says it consumed the key. An event naming a handler or a node this runtime does not have is an error, and so is a payload that no handler can receive.
Provided Methods§
Sourcefn size_token(&self, node_id: u32) -> Option<u32>
fn size_token(&self, node_id: u32) -> Option<u32>
The application’s name for a node it asked to have measured, if it asked.
Sourcefn poll_work(&mut self, context: &mut Context<'_>) -> Poll<()>
fn poll_work(&mut self, context: &mut Context<'_>) -> Poll<()>
Whether the runtime has work waiting that a frame should run. A runtime that is woken by something outside a boundary call (a timer, a task it spawned) wakes the context’s waker, and the Host turns that into a frame request.
Sourcefn run_in_context(&mut self, action: &mut dyn FnMut())
fn run_in_context(&mut self, action: &mut dyn FnMut())
Runs code the application handed to the Host, a message’s action for one, inside whatever context this runtime’s state writes need.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".