ritsu
ritsu copied to clipboard
buffer management and API design
Designing an ergonomic API for proactor has always been a challenge.
I think that transferring ownership is the only way, whether the future holds ownership of buffer, or the scope holds ownership of buffer.
I tried the new AsyncRead
/AsyncWrite
API (from @carllerche). I think this is right way.
pub trait AsyncRead {
fn poll_read(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Option<BytesMut>>>;
}
pub trait AsyncWrite {
fn submit(&mut self, buf: Bytes) -> io::Result<()>;
fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll<io::Result<Bytes>>;
}
This API is designed to work with buffer allocator. but allocator's design is a challenge, it should be general enough, and can take advantage from buffer select.
I decided not to implement the AsyncRead
/AsyncWrite
trait in 0.1.