webtransport_generic/
recv.rs1use std::{
2 future::{poll_fn, Future},
3 task::{Context, Poll},
4};
5
6use bytes::{BufMut, Bytes};
7
8use crate::ErrorCode;
9
10pub trait RecvStream: Unpin + Send {
12 type Error: ErrorCode;
13
14 fn close(self, code: u32);
16
17 fn poll_read_buf<B: BufMut>(
19 &mut self,
20 cx: &mut Context<'_>,
21 buf: &mut B,
22 ) -> Poll<Result<usize, Self::Error>>;
23
24 fn read_buf<B: BufMut + Send>(
26 &mut self,
27 buf: &mut B,
28 ) -> impl Future<Output = Result<usize, Self::Error>> + Send {
29 poll_fn(move |cx| self.poll_read_buf(cx, buf))
30 }
31
32 fn poll_read_chunk(&mut self, cx: &mut Context<'_>)
34 -> Poll<Result<Option<Bytes>, Self::Error>>;
35
36 fn read_chunk(&mut self) -> impl Future<Output = Result<Option<Bytes>, Self::Error>> + Send {
38 poll_fn(|cx| self.poll_read_chunk(cx))
39 }
40}