diff options
| author | bors <bors@rust-lang.org> | 2015-08-10 22:03:09 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-08-10 22:03:09 +0000 |
| commit | 75383ea7d7b1a4dff104be737830c1a31a6c0a73 (patch) | |
| tree | 1b64f2e3520c16a29495a84894dcb17acbf4fcff /src/libstd/io | |
| parent | 8856927f649d9ce80ff52377ac2389a2798a7033 (diff) | |
| parent | 664fdbed32aaa5f56e140b7f8f2c5e691f074154 (diff) | |
| download | rust-75383ea7d7b1a4dff104be737830c1a31a6c0a73.tar.gz rust-75383ea7d7b1a4dff104be737830c1a31a6c0a73.zip | |
Auto merge of #27531 - bluss:io-copy-dst, r=alexcrichton
std: Allow ?Sized parameters in std::io::copy
Diffstat (limited to 'src/libstd/io')
| -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 38e4b0d03e7..6e218f6ca7e 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -46,7 +46,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 { @@ -154,7 +156,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() { |
