intrepid_core/frame/
frame_outbox.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use futures::{channel::mpsc, SinkExt};
use tower::BoxError;

use super::Frame;

/// An outbox for sending frames to an actionable stream.
///
pub struct FrameOutbox(mpsc::Sender<Frame>);

impl FrameOutbox {
    /// Send a frame to the stream.
    pub async fn send(&mut self, frame: impl Into<Frame>) -> Result<(), BoxError> {
        self.0.send(frame.into()).await.map_err(Into::into)
    }

    /// Create a new frame outbox from a channel sender.
    pub fn new(tx: mpsc::Sender<Frame>) -> Self {
        Self(tx)
    }
}