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:
- Create a
JrHandlerChainwith the desired handlers - Call
.serve(channels)on it - 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§
Sourcefn serve(
self: Box<Self>,
channels: Channels,
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send>>
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.