pub trait DevtoolsBackend: Send + 'static {
// Required methods
fn widget_tree(&self) -> WidgetTreeDump;
fn widget_props(&self, id: u64) -> Option<WidgetProps>;
fn metrics_snapshot(&self) -> MetricsSnapshot;
fn inject_tap(&self, params: InputTapParams) -> Result<(), BackendError>;
fn inject_scroll(
&self,
params: InputScrollParams,
) -> Result<(), BackendError>;
fn inject_text(&self, text: &str) -> Result<(), BackendError>;
// Provided methods
fn handshake_info(&self, app: &AppInfo) -> HandshakeInfo { ... }
fn screenshot(&self) -> Result<ScreenshotResult, BackendError> { ... }
}Expand description
What the devtools service asks the app for.
§Threading
Every method here is called from the service’s own backend thread, one
call at a time, never from the frame/UI thread and never concurrently. An
implementation that needs UI-thread state does the hop itself (post to the
UI thread and block on the answer) — that is the one thing this trait
cannot do for it, because only the shell knows what its UI thread is. The
service caps every call with a timeout, so a hop that never comes back
costs the caller an error response, never a hung client
(crate::hop::BackendClient).
handshake_info is the exception: it is called once, on the thread that
calls crate::Service::start, and the answer is cached for the process
lifetime — which is what lets handshake be answered statelessly at any
time, including while the UI thread is wedged.
Required Methods§
Sourcefn widget_tree(&self) -> WidgetTreeDump
fn widget_tree(&self) -> WidgetTreeDump
A snapshot of the retained widget tree.
Infallible on purpose: “nothing built yet” is an empty
WidgetTreeDump::roots, not an error — a client polling a
just-launched app should see an empty tree, not a failure it has to
distinguish from a broken backend.
Sourcefn widget_props(&self, id: u64) -> Option<WidgetProps>
fn widget_props(&self, id: u64) -> Option<WidgetProps>
One widget’s inspectable properties, or None when id names no live
widget (the service turns that into INVALID_PARAMS — a stale id from
a tree the app has since rebuilt is an ordinary, expected case, not a
backend failure).
Sourcefn metrics_snapshot(&self) -> MetricsSnapshot
fn metrics_snapshot(&self) -> MetricsSnapshot
Process-level metrics (uptime, best-effort RSS). Infallible for
Self::widget_tree’s reason — an unavailable RSS is
MetricsSnapshot::rss_bytes None, not a failed call.
Sourcefn inject_tap(&self, params: InputTapParams) -> Result<(), BackendError>
fn inject_tap(&self, params: InputTapParams) -> Result<(), BackendError>
Synthesize a tap at the given logical-px point.
Sourcefn inject_scroll(&self, params: InputScrollParams) -> Result<(), BackendError>
fn inject_scroll(&self, params: InputScrollParams) -> Result<(), BackendError>
Synthesize a scroll at the given logical-px point.
Sourcefn inject_text(&self, text: &str) -> Result<(), BackendError>
fn inject_text(&self, text: &str) -> Result<(), BackendError>
Synthesize text input against the focused widget.
Provided Methods§
Sourcefn handshake_info(&self, app: &AppInfo) -> HandshakeInfo
fn handshake_info(&self, app: &AppInfo) -> HandshakeInfo
Server identity + the capability set clients gate on. Called once at startup, on the starting thread (see the trait doc).
The default answers with everything except
Capability::Screenshot, matching the default Self::screenshot
below — override this together with screenshot, never one alone.
Sourcefn screenshot(&self) -> Result<ScreenshotResult, BackendError>
fn screenshot(&self) -> Result<ScreenshotResult, BackendError>
Capture the current frame as a PNG.
Defaults to BackendError::NotSupported: a screenshot needs a
readback path the backend may not have, so it is capability-gated
rather than mandatory (RpcError::NOT_SUPPORTED on the wire). A
backend that overrides this must also declare
Capability::Screenshot in Self::handshake_info.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".