use std::{
future::{poll_fn, Future},
task::{Context, Poll},
};
use bytes::Buf;
use crate::ErrorCode;
pub trait SendStream: Unpin + Send {
type Error: ErrorCode;
fn priority(&mut self, order: i32);
fn close(self, code: u32);
fn poll_write(&mut self, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, Self::Error>>;
fn write(&mut self, buf: &[u8]) -> impl Future<Output = Result<usize, Self::Error>> + Send {
poll_fn(|cx| self.poll_write(cx, buf))
}
fn poll_write_buf<B: Buf>(
&mut self,
cx: &mut Context<'_>,
buf: &mut B,
) -> Poll<Result<usize, Self::Error>>;
fn write_buf<B: Buf + Send>(
&mut self,
buf: &mut B,
) -> impl Future<Output = Result<usize, Self::Error>> + Send {
poll_fn(|cx| self.poll_write_buf(cx, buf))
}
}