Skip to content

Commit 0dfa997

Browse files
committed
std: Stabilize portions of the io module
The new `io` module has had some time to bake and this commit stabilizes some of the utilities associated with it. This commit also deprecates a number of `std::old_io::util` functions and structures. These items are now `#[stable]` * `Cursor` * `Cursor::{new, into_inner, get_ref, get_mut, position, set_position}` * Implementations of I/O traits for `Cursor<T>` * Delegating implementations of I/O traits for references and `Box` pointers * Implementations of I/O traits for primitives like slices and `Vec<T>` * `ReadExt::bytes` * `Bytes` (and impls) * `ReadExt::chain` * `Chain` (and impls) * `ReadExt::take` (and impls) * `BufReadExt::lines` * `Lines` (and impls) * `io::copy` * `io::{empty, Empty}` (and impls) * `io::{sink, Sink}` (and impls) * `io::{repeat, Repeat}` (and impls) These items remain `#[unstable]` * Core I/O traits. These may want a little bit more time to bake along with the commonly used methods like `read_to_end`. * `BufReadExt::split` - this function may be renamed to not conflict with `SliceExt::split`. * `Error` - there are a number of questions about its representation, `ErrorKind`, and usability. These items are now `#[deprecated]` in `old_io` * `LimitReader` - use `take` instead * `NullWriter` - use `io::sink` instead * `ZeroReader` - use `io::repeat` instead * `NullReader` - use `io::empty` instead * `MultiWriter` - use `broadcast` instead * `ChainedReader` - use `chain` instead * `TeeReader` - use `tee` instead * `copy` - use `io::copy` instead [breaking-change]
1 parent 129173f commit 0dfa997

File tree

7 files changed

+167
-18
lines changed

7 files changed

+167
-18
lines changed

src/librustc_driver/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,7 @@ fn parse_crate_attrs(sess: &Session, input: &Input) ->
769769
///
770770
/// The diagnostic emitter yielded to the procedure should be used for reporting
771771
/// errors of the compiler.
772+
#[allow(deprecated)]
772773
pub fn monitor<F:FnOnce()+Send+'static>(f: F) {
773774
const STACK_SIZE: uint = 8 * 1024 * 1024; // 8MB
774775

src/librustdoc/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub fn run(input: &str,
106106
0
107107
}
108108

109+
#[allow(deprecated)]
109110
fn runtest(test: &str, cratename: &str, libs: SearchPaths,
110111
externs: core::Externs,
111112
should_fail: bool, no_run: bool, as_test_harness: bool) {

src/libstd/io/cursor.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![allow(missing_copy_implementations)]
12-
1311
use prelude::v1::*;
1412
use io::prelude::*;
1513

@@ -32,33 +30,40 @@ use slice;
3230
/// Implementations of the I/O traits for `Cursor<T>` are not currently generic
3331
/// over `T` itself. Instead, specific implementations are provided for various
3432
/// in-memory buffer types like `Vec<u8>` and `&[u8]`.
33+
#[stable(feature = "rust1", since = "1.0.0")]
3534
pub struct Cursor<T> {
3635
inner: T,
3736
pos: u64,
3837
}
3938

4039
impl<T> Cursor<T> {
4140
/// Create a new cursor wrapping the provided underlying I/O object.
41+
#[stable(feature = "rust1", since = "1.0.0")]
4242
pub fn new(inner: T) -> Cursor<T> {
4343
Cursor { pos: 0, inner: inner }
4444
}
4545

4646
/// Consume this cursor, returning the underlying value.
47+
#[stable(feature = "rust1", since = "1.0.0")]
4748
pub fn into_inner(self) -> T { self.inner }
4849

4950
/// Get a reference to the underlying value in this cursor.
51+
#[stable(feature = "rust1", since = "1.0.0")]
5052
pub fn get_ref(&self) -> &T { &self.inner }
5153

5254
/// Get a mutable reference to the underlying value in this cursor.
5355
///
5456
/// Care should be taken to avoid modifying the internal I/O state of the
5557
/// underlying value as it may corrupt this cursor's position.
58+
#[stable(feature = "rust1", since = "1.0.0")]
5659
pub fn get_mut(&mut self) -> &mut T { &mut self.inner }
5760

5861
/// Returns the current value of this cursor
62+
#[stable(feature = "rust1", since = "1.0.0")]
5963
pub fn position(&self) -> u64 { self.pos }
6064

6165
/// Sets the value of this cursor
66+
#[stable(feature = "rust1", since = "1.0.0")]
6267
pub fn set_position(&mut self, pos: u64) { self.pos = pos; }
6368
}
6469

@@ -83,8 +88,11 @@ macro_rules! seek {
8388
}
8489
}
8590

91+
#[stable(feature = "rust1", since = "1.0.0")]
8692
impl<'a> io::Seek for Cursor<&'a [u8]> { seek!(); }
93+
#[stable(feature = "rust1", since = "1.0.0")]
8794
impl<'a> io::Seek for Cursor<&'a mut [u8]> { seek!(); }
95+
#[stable(feature = "rust1", since = "1.0.0")]
8896
impl io::Seek for Cursor<Vec<u8>> { seek!(); }
8997

9098
macro_rules! read {
@@ -97,8 +105,11 @@ macro_rules! read {
97105
}
98106
}
99107

108+
#[stable(feature = "rust1", since = "1.0.0")]
100109
impl<'a> Read for Cursor<&'a [u8]> { read!(); }
110+
#[stable(feature = "rust1", since = "1.0.0")]
101111
impl<'a> Read for Cursor<&'a mut [u8]> { read!(); }
112+
#[stable(feature = "rust1", since = "1.0.0")]
102113
impl Read for Cursor<Vec<u8>> { read!(); }
103114

104115
macro_rules! buffer {
@@ -111,10 +122,14 @@ macro_rules! buffer {
111122
}
112123
}
113124

125+
#[stable(feature = "rust1", since = "1.0.0")]
114126
impl<'a> BufRead for Cursor<&'a [u8]> { buffer!(); }
127+
#[stable(feature = "rust1", since = "1.0.0")]
115128
impl<'a> BufRead for Cursor<&'a mut [u8]> { buffer!(); }
129+
#[stable(feature = "rust1", since = "1.0.0")]
116130
impl<'a> BufRead for Cursor<Vec<u8>> { buffer!(); }
117131

132+
#[stable(feature = "rust1", since = "1.0.0")]
118133
impl<'a> Write for Cursor<&'a mut [u8]> {
119134
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
120135
let pos = cmp::min(self.pos, self.inner.len() as u64);
@@ -125,6 +140,7 @@ impl<'a> Write for Cursor<&'a mut [u8]> {
125140
fn flush(&mut self) -> io::Result<()> { Ok(()) }
126141
}
127142

143+
#[stable(feature = "rust1", since = "1.0.0")]
128144
impl Write for Cursor<Vec<u8>> {
129145
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
130146
// Make sure the internal buffer is as least as big as where we

src/libstd/io/impls.rs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,88 @@ use vec::Vec;
2222
// =============================================================================
2323
// Forwarding implementations
2424

25+
#[stable(feature = "rust1", since = "1.0.0")]
2526
impl<'a, R: Read + ?Sized> Read for &'a mut R {
26-
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { (**self).read(buf) }
27-
28-
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<()> { (**self).read_to_end(buf) }
29-
27+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
28+
(**self).read(buf)
29+
}
30+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<()> {
31+
(**self).read_to_end(buf)
32+
}
3033
fn read_to_string(&mut self, buf: &mut String) -> io::Result<()> {
3134
(**self).read_to_string(buf)
3235
}
3336
}
37+
#[stable(feature = "rust1", since = "1.0.0")]
3438
impl<'a, W: Write + ?Sized> Write for &'a mut W {
3539
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
36-
37-
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { (**self).write_all(buf) }
38-
39-
fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> { (**self).write_fmt(fmt) }
40-
4140
fn flush(&mut self) -> io::Result<()> { (**self).flush() }
41+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
42+
(**self).write_all(buf)
43+
}
44+
fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> {
45+
(**self).write_fmt(fmt)
46+
}
4247
}
48+
#[stable(feature = "rust1", since = "1.0.0")]
4349
impl<'a, S: Seek + ?Sized> Seek for &'a mut S {
4450
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
4551
}
52+
#[stable(feature = "rust1", since = "1.0.0")]
4653
impl<'a, B: BufRead + ?Sized> BufRead for &'a mut B {
4754
fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
48-
4955
fn consume(&mut self, amt: usize) { (**self).consume(amt) }
50-
5156
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<()> {
5257
(**self).read_until(byte, buf)
5358
}
54-
55-
fn read_line(&mut self, buf: &mut String) -> io::Result<()> { (**self).read_line(buf) }
59+
fn read_line(&mut self, buf: &mut String) -> io::Result<()> {
60+
(**self).read_line(buf)
61+
}
5662
}
5763

64+
#[stable(feature = "rust1", since = "1.0.0")]
5865
impl<R: Read + ?Sized> Read for Box<R> {
59-
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { (**self).read(buf) }
66+
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
67+
(**self).read(buf)
68+
}
69+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<()> {
70+
(**self).read_to_end(buf)
71+
}
72+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<()> {
73+
(**self).read_to_string(buf)
74+
}
6075
}
76+
#[stable(feature = "rust1", since = "1.0.0")]
6177
impl<W: Write + ?Sized> Write for Box<W> {
6278
fn write(&mut self, buf: &[u8]) -> io::Result<usize> { (**self).write(buf) }
6379
fn flush(&mut self) -> io::Result<()> { (**self).flush() }
80+
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
81+
(**self).write_all(buf)
82+
}
83+
fn write_fmt(&mut self, fmt: fmt::Arguments) -> io::Result<()> {
84+
(**self).write_fmt(fmt)
85+
}
6486
}
87+
#[stable(feature = "rust1", since = "1.0.0")]
6588
impl<S: Seek + ?Sized> Seek for Box<S> {
6689
fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> { (**self).seek(pos) }
6790
}
91+
#[stable(feature = "rust1", since = "1.0.0")]
6892
impl<B: BufRead + ?Sized> BufRead for Box<B> {
6993
fn fill_buf(&mut self) -> io::Result<&[u8]> { (**self).fill_buf() }
7094
fn consume(&mut self, amt: usize) { (**self).consume(amt) }
95+
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> io::Result<()> {
96+
(**self).read_until(byte, buf)
97+
}
98+
fn read_line(&mut self, buf: &mut String) -> io::Result<()> {
99+
(**self).read_line(buf)
100+
}
71101
}
72102

73103
// =============================================================================
74104
// In-memory buffer implementations
75105

106+
#[stable(feature = "rust1", since = "1.0.0")]
76107
impl<'a> Read for &'a [u8] {
77108
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
78109
let amt = cmp::min(buf.len(), self.len());
@@ -83,11 +114,13 @@ impl<'a> Read for &'a [u8] {
83114
}
84115
}
85116

117+
#[stable(feature = "rust1", since = "1.0.0")]
86118
impl<'a> BufRead for &'a [u8] {
87119
fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(*self) }
88120
fn consume(&mut self, amt: usize) { *self = &self[amt..]; }
89121
}
90122

123+
#[stable(feature = "rust1", since = "1.0.0")]
91124
impl<'a> Write for &'a mut [u8] {
92125
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
93126
let amt = cmp::min(data.len(), self.len());
@@ -108,14 +141,15 @@ impl<'a> Write for &'a mut [u8] {
108141
fn flush(&mut self) -> io::Result<()> { Ok(()) }
109142
}
110143

144+
#[stable(feature = "rust1", since = "1.0.0")]
111145
impl Write for Vec<u8> {
112146
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
113147
self.push_all(buf);
114148
Ok(buf.len())
115149
}
116150

117151
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
118-
try!(self.write(buf));
152+
self.push_all(buf);
119153
Ok(())
120154
}
121155

0 commit comments

Comments
 (0)