use std::task::Waker;
use std::task::Poll;
use std::task::Context;
use std::io;
use std::pin::Pin;
use tokio::io::{ReadBuf, AsyncRead, AsyncWrite};
use crate::{File, poll_io};
impl tokio::io::AsyncRead for File {
fn poll_read(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &mut ReadBuf<'_>
) -> Poll<io::Result<()>> {
let bbuf = buf.initialize_unfilled();
poll_io(
self.fd, ctx,
self.raw_read(bbuf),
|n| { buf.advance(n.try_into().unwrap()); })
}
}
impl AsyncWrite for File {
fn poll_write(
self: Pin<&mut Self>,
ctx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, io::Error>> {
poll_io(
self.fd, ctx,
self.raw_write(buf),
|n| n.try_into().unwrap())
}
fn poll_flush(
self: Pin<&mut Self>,
ctx: &mut Context<'_>
) -> Poll<Result<(), io::Error>> {
Poll::Ready(Ok(()))
}
fn poll_shutdown(
self: Pin<&mut Self>,
ctx: &mut Context<'_>
) -> Poll<Result<(), io::Error>> {
Poll::Ready(Ok(()))
}
}