1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use crate::TypedAsyncRead;
use async_trait::async_trait;
use std::io;
use tokio::sync::mpsc;

#[derive(Debug)]
pub struct MpscTransportReadHalf<T> {
    rx: mpsc::Receiver<T>,
}

impl<T> MpscTransportReadHalf<T> {
    pub fn new(rx: mpsc::Receiver<T>) -> Self {
        Self { rx }
    }
}

#[async_trait]
impl<T: Send> TypedAsyncRead<T> for MpscTransportReadHalf<T> {
    async fn read(&mut self) -> io::Result<Option<T>> {
        Ok(self.rx.recv().await)
    }
}