use std::task::{Context, Poll};
use bytes::Buf;
pub use http3::quic::{
ConnectionErrorIncoming as ConnectionError, StreamErrorIncoming as StreamError, StreamId,
};
pub use self::compat::Compat;
#[cfg(feature = "http3-datagram")]
pub use self::datagram::{DatagramConnection, DatagramError, RecvDatagram, SendDatagram};
mod compat;
#[cfg(feature = "http3-datagram")]
mod datagram;
pub trait Connection<B: Buf>: OpenStreams<B> {
type RecvStream: RecvStream;
type OpenStreams: OpenStreams<B, SendStream = Self::SendStream, BidiStream = Self::BidiStream>;
fn poll_accept_recv(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Self::RecvStream>, ConnectionError>>;
fn poll_accept_bidi(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Self::BidiStream>, ConnectionError>>;
fn opener(&self) -> Self::OpenStreams;
}
pub trait OpenStreams<B: Buf> {
type SendStream: SendStream<B>;
type BidiStream: BidiStream<B>;
fn poll_open_bidi(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Self::BidiStream, StreamError>>;
fn poll_open_send(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Self::SendStream, StreamError>>;
fn close(&mut self, code: u64, reason: &[u8]);
}
pub trait SendStream<B: Buf> {
fn poll_send<D: Buf>(
&mut self,
cx: &mut Context<'_>,
buf: &mut D,
) -> Poll<Result<usize, StreamError>>;
fn poll_stopped(&mut self, cx: &mut Context<'_>) -> Poll<Result<Option<u64>, StreamError>>;
fn poll_finish(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), StreamError>>;
fn reset(&mut self, code: u64);
fn send_id(&self) -> StreamId;
}
pub trait RecvStream {
type Buf: Buf;
fn poll_data(&mut self, cx: &mut Context<'_>) -> Poll<Result<Option<Self::Buf>, StreamError>>;
fn stop_sending(&mut self, code: u64);
fn recv_id(&self) -> StreamId;
}
pub trait BidiStream<B: Buf>: SendStream<B> + RecvStream {
type SendStream: SendStream<B>;
type RecvStream: RecvStream;
fn split(self) -> (Self::SendStream, Self::RecvStream);
}