io: implement AsyncWrite for Vec<u8> (#1409)

This commit is contained in:
tmiasko
2019-08-08 20:55:27 -07:00
committed by Carl Lerche
parent 790d649dc5
commit eba8bf2b4b
2 changed files with 22 additions and 27 deletions
+19
View File
@@ -190,3 +190,22 @@ where
self.get_mut().as_mut().poll_shutdown(cx)
}
}
impl AsyncWrite for Vec<u8> {
fn poll_write(
self: Pin<&mut Self>,
_cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<io::Result<usize>> {
self.get_mut().extend_from_slice(buf);
Poll::Ready(Ok(buf.len()))
}
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Poll::Ready(Ok(()))
}
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
Poll::Ready(Ok(()))
}
}