Skip to main content

DaemonService

Trait DaemonService 

Source
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 method
    fn subscribe(
        &self,
        _op: &str,
        _payload: &Value,
    ) -> Option<Box<dyn ServiceStream>> { ... }
}
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§

Source

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.

Source

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.

Source

fn menu(&self) -> MenuSnapshot

Cheap snapshot of the service’s tray submenu, polled by the menu-bar shell. Must not block.

Source

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,

Performs a tray menu action previously surfaced by menu, identified by its MenuAction::id.

Source

fn status<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ServiceStatus> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Structured status for daemon status aggregation.

Source

fn shutdown<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gracefully stops the service, draining in-flight work. Called once on daemon shutdown.

Provided Methods§

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§