diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-08-05 13:31:05 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2015-08-10 14:29:08 +0200 |
| commit | 664fdbed32aaa5f56e140b7f8f2c5e691f074154 (patch) | |
| tree | 3153a395e56ffc1d4f13dc391ca47a6ec66bba4f | |
| parent | 832e5a02cd41b3a20d1142b47867da4aa5033f03 (diff) | |
| download | rust-664fdbed32aaa5f56e140b7f8f2c5e691f074154.tar.gz rust-664fdbed32aaa5f56e140b7f8f2c5e691f074154.zip | |
std: Allow ?Sized parameters in std::io::copy
std::io::copy did not allow passing trait objects directly (only with an extra &mut wrapping).
| -rw-r--r-- | src/libstd/io/util.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 6e651464c74..39833cd2cc7 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -45,7 +45,9 @@ use io::{self, Read, Write, ErrorKind, BufRead}; /// # } /// ``` #[stable(feature = "rust1", since = "1.0.0")] -pub fn copy<R: Read, W: Write>(reader: &mut R, writer: &mut W) -> io::Result<u64> { +pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64> + where R: Read, W: Write +{ let mut buf = [0; super::DEFAULT_BUF_SIZE]; let mut written = 0; loop { @@ -153,7 +155,17 @@ mod tests { use prelude::v1::*; use io::prelude::*; - use io::{sink, empty, repeat}; + use io::{copy, sink, empty, repeat}; + + #[test] + fn copy_copies() { + let mut r = repeat(0).take(4); + let mut w = sink(); + assert_eq!(copy(&mut r, &mut w).unwrap(), 4); + + let mut r = repeat(0).take(1 << 17); + assert_eq!(copy(&mut r as &mut Read, &mut w as &mut Write).unwrap(), 1 << 17); + } #[test] fn sink_sinks() { |
