Skip to content

Commit

Permalink
Auto merge of #27531 - bluss:io-copy-dst, r=alexcrichton
Browse files Browse the repository at this point in the history
std: Allow ?Sized parameters in std::io::copy
  • Loading branch information
bors committed Aug 10, 2015
2 parents 8856927 + 664fdbe commit 75383ea
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/libstd/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 75383ea

Please sign in to comment.