fixed-buffer 0.5.0

Fixed-size buffers for network protocol parsers
Documentation
use crate::FixedBuf;
use std::pin::Pin;
use std::task::{Context, Poll};

impl<const SIZE: usize> futures_io::AsyncRead for FixedBuf<SIZE> {
    fn poll_read(
        mut self: Pin<&mut Self>,
        _cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<Result<usize, std::io::Error>> {
        Poll::Ready(Ok(self.read_and_copy_bytes(buf)))
    }
}

impl<const SIZE: usize> futures_io::AsyncWrite for FixedBuf<SIZE> {
    fn poll_write(
        mut self: Pin<&mut Self>,
        _cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize, std::io::Error>> {
        Poll::Ready(Ok(self.write_bytes(buf)?))
    }

    fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
        Poll::Ready(Ok(()))
    }

    fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), std::io::Error>> {
        Poll::Ready(Ok(()))
    }
}