rmqtt_net/
quic.rs

1use quinn::{RecvStream, SendStream};
2use std::{
3    pin::Pin,
4    task::{Context, Poll},
5};
6use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
7
8#[allow(dead_code)]
9pub struct QuinnBiStream {
10    send: SendStream,
11    recv: RecvStream,
12}
13
14impl QuinnBiStream {
15    #[allow(dead_code)]
16    pub fn new(send: SendStream, recv: RecvStream) -> Self {
17        Self { send, recv }
18    }
19}
20
21impl AsyncRead for QuinnBiStream {
22    fn poll_read(
23        mut self: Pin<&mut Self>,
24        cx: &mut Context<'_>,
25        buf: &mut ReadBuf<'_>,
26    ) -> Poll<std::io::Result<()>> {
27        Pin::new(&mut self.recv).poll_read_buf(cx, buf).map_err(std::io::Error::other)
28    }
29}
30
31impl AsyncWrite for QuinnBiStream {
32    fn poll_write(
33        mut self: Pin<&mut Self>,
34        cx: &mut Context<'_>,
35        buf: &[u8],
36    ) -> Poll<Result<usize, std::io::Error>> {
37        Pin::new(&mut self.send).poll_write(cx, buf).map_err(std::io::Error::other)
38    }
39
40    fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
41        Pin::new(&mut self.send).poll_flush(cx).map_err(std::io::Error::other)
42    }
43
44    fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
45        Pin::new(&mut self.send).poll_shutdown(cx).map_err(std::io::Error::other)
46    }
47}
48
49impl Unpin for QuinnBiStream {}