-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement AsyncWrite for the generic Cursor<T: AsMut<[u8]>>
This introduces an unfortunate point of difference between `futures::io::AsyncWrite` and `std::io::Write`, but I think the increased ergonomics around writing to statically sized in memory buffers (presumably just for test purposes) is useful. `impl<T: AsRef<[u8]>> Read for Cursor<T>` was added in rust-lang/rust#27197, I'm not sure why `impl<T: AsMut<[u8]>> Write for Cursor<T>` wasn't added at the same time; I would propose doing this change in `std` and just piggybacking off it here, but the breakage is almost certainly not worth it by this point.
- Loading branch information
Showing
4 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![feature(use_extern_macros, futures_api)] | ||
|
||
use assert_matches::assert_matches; | ||
use futures::Poll; | ||
use futures::future::lazy; | ||
use futures::io::AsyncWrite; | ||
use std::io::Cursor; | ||
|
||
#[test] | ||
fn cursor_asyncwrite_asmut() { | ||
let mut cursor = Cursor::new([0; 5]); | ||
futures::executor::block_on(lazy(|ctx| { | ||
assert_matches!(cursor.poll_write(ctx, &[1, 2]), Poll::Ready(Ok(2))); | ||
assert_matches!(cursor.poll_write(ctx, &[3, 4]), Poll::Ready(Ok(2))); | ||
assert_matches!(cursor.poll_write(ctx, &[5, 6]), Poll::Ready(Ok(1))); | ||
assert_matches!(cursor.poll_write(ctx, &[6, 7]), Poll::Ready(Ok(0))); | ||
})); | ||
assert_eq!(cursor.into_inner(), [1, 2, 3, 4, 5]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters