Component

Trait Component 

Source
pub trait Component: Send {
    // Required method
    fn serve(
        self: Box<Self>,
        channels: Channels,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>;
}
Expand description

Re-export component types from sacp A component that can be run as part of a conductor’s chain.

Components are always servers that receive Channels for bidirectional communication with their conductor. The channels carry JSON-RPC messages between the conductor and component.

§Implementation

Most implementations will:

  1. Create a JrHandlerChain with the desired handlers
  2. Call .serve(channels) on it
  3. Return the resulting future wrapped in a BoxFuture

§Examples

Basic component implementation:

use sacp::component::Component;
use sacp::{Channels, JrHandlerChain};
use futures::future::BoxFuture;

struct MyComponent;

impl Component for MyComponent {
    fn serve(self: Box<Self>, channels: Channels) -> BoxFuture<'static, Result<(), sacp::Error>> {
        Box::pin(async move {
            JrHandlerChain::new()
                .name("my-component")
                .on_receive_request(async |req: MyRequest, cx| {
                    cx.respond(MyResponse { status: "ok".into() })
                })
                .serve(channels)
                .await
        })
    }
}

Required Methods§

Source

fn serve( self: Box<Self>, channels: Channels, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

Serve this component on the given channels.

The component should set up its handler chain and serve on the provided channels, which connect it to its conductor.

§Arguments
  • channels - Bidirectional message channels for communicating with the conductor
§Returns

A future that resolves when the component stops serving, either successfully or with an error.

Trait Implementations§

Source§

impl Transport for dyn Component

Blanket implementation: any Component can be used as a Transport.

Since both Channels and Channels now have the same signature (both use Result<Message, Error> for incoming), we can directly pass through.

Source§

fn transport( self: Box<dyn Component>, channels: Channels, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>

Run the transport, bridging the connection’s message channels with the underlying I/O. Read more

Implementors§

Source§

impl<T> Component for T
where T: Transport + 'static,

Blanket implementation: any Transport can be used as a Component.

Since both Channels and Channels now have the same signature (both use Result<Message, Error> for incoming), we can directly pass through.