use std::{
future::{poll_fn, Future},
task::{Context, Poll},
};
use bytes::{BufMut, Bytes};
use crate::ErrorCode;
pub trait RecvStream: Unpin + Send {
type Error: ErrorCode;
fn close(self, code: u32);
fn poll_read_buf<B: BufMut>(
&mut self,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<Result<usize, Self::Error>>;
fn read_buf<B: BufMut + Send>(
&mut self,
buf: &mut B,
) -> impl Future<Output = Result<usize, Self::Error>> + Send {
poll_fn(move |cx| self.poll_read_buf(cx, buf))
}
fn poll_read_chunk(&mut self, cx: &mut Context<'_>)
-> Poll<Result<Option<Bytes>, Self::Error>>;
fn read_chunk(&mut self) -> impl Future<Output = Result<Option<Bytes>, Self::Error>> + Send {
poll_fn(|cx| self.poll_read_chunk(cx))
}
}