Skip to content

Commit

Permalink
Test specialization for AsyncWrite with Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed May 16, 2019
1 parent c372c48 commit 7997066
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 23 additions & 1 deletion futures-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#![cfg_attr(not(feature = "std"), no_std)]

#![feature(specialization)]

#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#![warn(clippy::all)]

Expand Down Expand Up @@ -505,7 +507,7 @@ mod if_std {
}

impl<T: AsMut<[u8]> + Unpin> AsyncWrite for StdIo::Cursor<T> {
fn poll_write(
default fn poll_write(
mut self: Pin<&mut Self>,
_: &mut Context<'_>,
buf: &[u8],
Expand Down Expand Up @@ -537,6 +539,26 @@ mod if_std {
}
}

impl AsyncWrite for StdIo::Cursor<&mut Vec<u8>> {
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>> {
Poll::Ready(StdIo::Write::write(self.get_mut(), buf))
}
}

impl AsyncWrite for StdIo::Cursor<Vec<u8>> {
fn poll_write(
self: Pin<&mut Self>,
_: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize>> {
Poll::Ready(StdIo::Write::write(self.get_mut(), buf))
}
}

impl AsyncWrite for Vec<u8> {
delegate_async_write_to_stdio!();
}
Expand Down
4 changes: 1 addition & 3 deletions futures/tests/io_buf_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,7 @@ impl AsyncSeek for MaybePendingSeek {

#[test]
fn maybe_pending_buf_writer_seek() {
// FIXME: when https://github.com/rust-lang-nursery/futures-rs/issues/1510 fixed,
// use `Vec::new` instead of `vec![0; 8]`.
let mut w = BufWriter::with_capacity(3, MaybePendingSeek::new(vec![0; 8]));
let mut w = BufWriter::with_capacity(3, MaybePendingSeek::new(Vec::new()));
run(w.write_all(&[0, 1, 2, 3, 4, 5])).unwrap();
run(w.write_all(&[6, 7])).unwrap();
assert_eq!(run(w.seek(SeekFrom::Current(0))).ok(), Some(8));
Expand Down

0 comments on commit 7997066

Please sign in to comment.