intrepid_core/frame/frame_outbox.rs
1use futures::{channel::mpsc, SinkExt};
2use tower::BoxError;
3
4use super::Frame;
5
6/// An outbox for sending frames to an actionable stream.
7///
8pub struct FrameOutbox(mpsc::Sender<Frame>);
9
10impl FrameOutbox {
11 /// Send a frame to the stream.
12 pub async fn send(&mut self, frame: impl Into<Frame>) -> Result<(), BoxError> {
13 self.0.send(frame.into()).await.map_err(Into::into)
14 }
15
16 /// Create a new frame outbox from a channel sender.
17 pub fn new(tx: mpsc::Sender<Frame>) -> Self {
18 Self(tx)
19 }
20}