pub trait DaemonService: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
op: &'life1 str,
payload: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn menu(&self) -> MenuSnapshot;
fn menu_action<'life0, 'life1, 'async_trait>(
&'life0 self,
action_id: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn status<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ServiceStatus> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn shutdown<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn subscribe(
&self,
_op: &str,
_payload: &Value,
) -> Option<Box<dyn ServiceStream>> { ... }
fn credit_accept_outage(&self, _outage: Duration) { ... }
}Expand description
A long-lived unit of work supervised by the daemon.
Implementations are registered in a ServiceRegistry
and are assumed live from registration until shutdown.
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Stable identifier used to route control-socket envelopes to this service
(the envelope’s service field) and to label its status/menu.
Sourcefn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
op: &'life1 str,
payload: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn handle<'life0, 'life1, 'async_trait>(
&'life0 self,
op: &'life1 str,
payload: Value,
) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Handles an operation routed to this service, returning a JSON payload.
Cheap snapshot of the service’s tray submenu, polled by the menu-bar shell. Must not block.
Performs a tray menu action previously surfaced by menu,
identified by its MenuAction::id.
Provided Methods§
Sourcefn subscribe(
&self,
_op: &str,
_payload: &Value,
) -> Option<Box<dyn ServiceStream>>
fn subscribe( &self, _op: &str, _payload: &Value, ) -> Option<Box<dyn ServiceStream>>
Opens a push subscription for a streaming op, or returns None when
op is not one this service streams (the default for every service).
When the server sees a Some, it switches that connection to streaming
mode (server::run_stream): it sends the stream’s
initial snapshot, then pushes a fresh
snapshot each time ServiceStream::changed (or the server’s own
periodic tick) wakes it and the payload differs from the last one sent,
until the client disconnects or the daemon shuts down. A None op falls
through to the normal request→one-reply handle path, so
the request/reply contract is unchanged for every existing service and op
(#1267).
Kept synchronous and cheap: building a stream should only clone the
handles it needs. payload is borrowed so the non-streaming path retains
ownership for handle.
Sourcefn credit_accept_outage(&self, _outage: Duration)
fn credit_accept_outage(&self, _outage: Duration)
Told that the control socket could not accept connections for outage
(descriptor exhaustion, #2111), so no client could have reached this
service for that long.
A service that ages entries out by how long a client has been silent should credit the outage, or it will blame clients for silence the daemon caused. The default does nothing, which is right for a service with no such liveness clock. Called from the accept loop, so it must be cheap and must not block.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".