use o3::buffer;
use crate::memory;
type Extent<P> = <P as Pending>::Extent;
type Rejection<P> = (
P,
<Extent<P> as memory::raw::Extent>::Length,
<Extent<P> as memory::raw::Extent>::Capacity,
);
pub trait Select {
type Index: Copy;
type Pending: Token<Index = Self::Index>
+ Pending<
Complete: Token<
Index = Self::Index,
Length = <Extent<Self::Pending> as memory::raw::Extent>::Length,
>,
>;
unsafe fn select(&self, index: Self::Index) -> Result<Self::Pending, Self::Index>;
}
pub unsafe trait Token {
type Index: Copy;
type Length: Copy;
fn index(&self) -> Self::Index;
fn length(&self) -> Self::Length;
}
pub trait Release<T> {
unsafe fn release(&mut self, buffer: T);
}
pub trait Context<T: Token>: buffer::raw::Fixed<T> {
unsafe fn bytes<'a>(&'a self, buffer: &'a T) -> &'a [u8];
}
pub trait Pending: Sized {
type Extent: memory::raw::Extent;
type Complete;
fn try_complete(
self,
len: <Self::Extent as memory::raw::Extent>::Length,
) -> Result<Self::Complete, Rejection<Self>>;
}