Skip to content

Commit 3e4be02

Browse files
committed
Auto merge of #23292 - alexcrichton:stabilize-io, r=aturon
The new `std::io` module has had some time to bake now, and this commit stabilizes its functionality. There are still portions of the module which remain unstable, and below contains a summart of the actions taken. This commit also deprecates the entire contents of the `old_io` module in a blanket fashion. All APIs should now have a reasonable replacement in the new I/O modules. Stable APIs: * `std::io` (the name) * `std::io::prelude` (the name) * `Read` * `Read::read` * `Read::{read_to_end, read_to_string}` after being modified to return a `usize` for the number of bytes read. * `ReadExt` * `Write` * `Write::write` * `Write::{write_all, write_fmt}` * `WriteExt` * `BufRead` * `BufRead::{fill_buf, consume}` * `BufRead::{read_line, read_until}` after being modified to return a `usize` for the number of bytes read. * `BufReadExt` * `BufReader` * `BufReader::{new, with_capacity}` * `BufReader::{get_ref, get_mut, into_inner}` * `{Read,BufRead} for BufReader` * `BufWriter` * `BufWriter::{new, with_capacity}` * `BufWriter::{get_ref, get_mut, into_inner}` * `Write for BufWriter` * `IntoInnerError` * `IntoInnerError::{error, into_inner}` * `{Error,Display} for IntoInnerError` * `LineWriter` * `LineWriter::{new, with_capacity}` - `with_capacity` was added * `LineWriter::{get_ref, get_mut, into_inner}` - `get_mut` was added) * `Write for LineWriter` * `BufStream` * `BufStream::{new, with_capacities}` * `BufStream::{get_ref, get_mut, into_inner}` * `{BufRead,Read,Write} for BufStream` * `stdin` * `Stdin` * `Stdin::lock` * `Stdin::read_line` - added method * `StdinLock` * `Read for Stdin` * `{Read,BufRead} for StdinLock` * `stdout` * `Stdout` * `Stdout::lock` * `StdoutLock` * `Write for Stdout` * `Write for StdoutLock` * `stderr` * `Stderr` * `Stderr::lock` * `StderrLock` * `Write for Stderr` * `Write for StderrLock` * `io::Result` * `io::Error` * `io::Error::last_os_error` * `{Display, Error} for Error` Unstable APIs: (reasons can be found in the commit itself) * `Write::flush` * `Seek` * `ErrorKind` * `Error::new` * `Error::from_os_error` * `Error::kind` Deprecated APIs * `Error::description` - available via the `Error` trait * `Error::detail` - available via the `Display` implementation * `thread::Builder::{stdout, stderr}` Changes in functionality: * `old_io::stdio::set_stderr` is now a noop as the infrastructure for printing backtraces has migrated to `std::io`. [breaking-change]
2 parents 9eb69ab + 981bf5f commit 3e4be02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+820
-898
lines changed

src/compiletest/compiletest.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#![feature(std_misc)]
2121
#![feature(test)]
2222
#![feature(core)]
23-
#![feature(io)]
2423
#![feature(net)]
2524
#![feature(path_ext)]
2625

@@ -34,7 +33,6 @@ extern crate log;
3433

3534
use std::env;
3635
use std::fs;
37-
use std::old_io;
3836
use std::path::{Path, PathBuf};
3937
use std::thunk::Thunk;
4038
use getopts::{optopt, optflag, reqopt};
@@ -246,7 +244,11 @@ pub fn run_tests(config: &Config) {
246244
// sadly osx needs some file descriptor limits raised for running tests in
247245
// parallel (especially when we have lots and lots of child processes).
248246
// For context, see #8904
249-
old_io::test::raise_fd_limit();
247+
#[allow(deprecated)]
248+
fn raise_fd_limit() {
249+
std::old_io::test::raise_fd_limit();
250+
}
251+
raise_fd_limit();
250252
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
251253
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
252254
env::set_var("__COMPAT_LAYER", "RunAsInvoker");

src/compiletest/runtest.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::io::BufReader;
2626
use std::io::prelude::*;
2727
use std::iter::repeat;
2828
use std::net::TcpStream;
29-
use std::old_io::timer;
3029
use std::path::{Path, PathBuf};
3130
use std::process::{Command, Output, ExitStatus};
3231
use std::str;
@@ -452,7 +451,11 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
452451
.expect(&format!("failed to exec `{:?}`", config.adb_path));
453452
loop {
454453
//waiting 1 second for gdbserver start
455-
timer::sleep(Duration::milliseconds(1000));
454+
#[allow(deprecated)]
455+
fn sleep() {
456+
::std::old_io::timer::sleep(Duration::milliseconds(1000));
457+
}
458+
sleep();
456459
if TcpStream::connect("127.0.0.1:5039").is_ok() {
457460
break
458461
}

src/libgraphviz/lib.rs

+35-28
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@
4848
//!
4949
//! ```rust
5050
//! use std::borrow::IntoCow;
51+
//! use std::io::Write;
5152
//! use graphviz as dot;
5253
//!
5354
//! type Nd = int;
5455
//! type Ed = (int,int);
5556
//! struct Edges(Vec<Ed>);
5657
//!
57-
//! pub fn render_to<W:Writer>(output: &mut W) {
58+
//! pub fn render_to<W: Write>(output: &mut W) {
5859
//! let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
5960
//! dot::render(&edges, output).unwrap()
6061
//! }
@@ -94,10 +95,10 @@
9495
//! ```
9596
//!
9697
//! ```no_run
97-
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
98+
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
9899
//! pub fn main() {
99-
//! use std::old_io::File;
100-
//! let mut f = File::create(&Path::new("example1.dot"));
100+
//! use std::fs::File;
101+
//! let mut f = File::create("example1.dot").unwrap();
101102
//! render_to(&mut f)
102103
//! }
103104
//! ```
@@ -148,13 +149,14 @@
148149
//!
149150
//! ```rust
150151
//! use std::borrow::IntoCow;
152+
//! use std::io::Write;
151153
//! use graphviz as dot;
152154
//!
153155
//! type Nd = uint;
154156
//! type Ed<'a> = &'a (uint, uint);
155157
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
156158
//!
157-
//! pub fn render_to<W:Writer>(output: &mut W) {
159+
//! pub fn render_to<W: Write>(output: &mut W) {
158160
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
159161
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
160162
//! let graph = Graph { nodes: nodes, edges: edges };
@@ -186,10 +188,10 @@
186188
//! ```
187189
//!
188190
//! ```no_run
189-
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
191+
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
190192
//! pub fn main() {
191-
//! use std::old_io::File;
192-
//! let mut f = File::create(&Path::new("example2.dot"));
193+
//! use std::fs::File;
194+
//! let mut f = File::create("example2.dot").unwrap();
193195
//! render_to(&mut f)
194196
//! }
195197
//! ```
@@ -204,13 +206,14 @@
204206
//!
205207
//! ```rust
206208
//! use std::borrow::IntoCow;
209+
//! use std::io::Write;
207210
//! use graphviz as dot;
208211
//!
209212
//! type Nd<'a> = (uint, &'a str);
210213
//! type Ed<'a> = (Nd<'a>, Nd<'a>);
211214
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
212215
//!
213-
//! pub fn render_to<W:Writer>(output: &mut W) {
216+
//! pub fn render_to<W: Write>(output: &mut W) {
214217
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
215218
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
216219
//! let graph = Graph { nodes: nodes, edges: edges };
@@ -250,10 +253,10 @@
250253
//! ```
251254
//!
252255
//! ```no_run
253-
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
256+
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
254257
//! pub fn main() {
255-
//! use std::old_io::File;
256-
//! let mut f = File::create(&Path::new("example3.dot"));
258+
//! use std::fs::File;
259+
//! let mut f = File::create("example3.dot").unwrap();
257260
//! render_to(&mut f)
258261
//! }
259262
//! ```
@@ -277,12 +280,12 @@
277280
html_root_url = "http://doc.rust-lang.org/nightly/")]
278281
#![feature(int_uint)]
279282
#![feature(collections)]
280-
#![feature(old_io)]
281283

282284
use self::LabelText::*;
283285

284286
use std::borrow::{IntoCow, Cow};
285-
use std::old_io;
287+
use std::io::prelude::*;
288+
use std::io;
286289

287290
/// The text for a graphviz label on a node or edge.
288291
pub enum LabelText<'a> {
@@ -529,26 +532,26 @@ pub fn default_options() -> Vec<RenderOption> { vec![] }
529532

530533
/// Renders directed graph `g` into the writer `w` in DOT syntax.
531534
/// (Simple wrapper around `render_opts` that passes a default set of options.)
532-
pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
535+
pub fn render<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>(
533536
g: &'a G,
534-
w: &mut W) -> old_io::IoResult<()> {
537+
w: &mut W) -> io::Result<()> {
535538
render_opts(g, w, &[])
536539
}
537540

538541
/// Renders directed graph `g` into the writer `w` in DOT syntax.
539542
/// (Main entry point for the library.)
540-
pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Writer>(
543+
pub fn render_opts<'a, N:Clone+'a, E:Clone+'a, G:Labeller<'a,N,E>+GraphWalk<'a,N,E>, W:Write>(
541544
g: &'a G,
542545
w: &mut W,
543-
options: &[RenderOption]) -> old_io::IoResult<()>
546+
options: &[RenderOption]) -> io::Result<()>
544547
{
545-
fn writeln<W:Writer>(w: &mut W, arg: &[&str]) -> old_io::IoResult<()> {
546-
for &s in arg { try!(w.write_str(s)); }
547-
w.write_char('\n')
548+
fn writeln<W:Write>(w: &mut W, arg: &[&str]) -> io::Result<()> {
549+
for &s in arg { try!(w.write_all(s.as_bytes())); }
550+
write!(w, "\n")
548551
}
549552

550-
fn indent<W:Writer>(w: &mut W) -> old_io::IoResult<()> {
551-
w.write_str(" ")
553+
fn indent<W:Write>(w: &mut W) -> io::Result<()> {
554+
w.write_all(b" ")
552555
}
553556

554557
try!(writeln(w, &["digraph ", g.graph_id().as_slice(), " {"]));
@@ -589,7 +592,8 @@ mod tests {
589592
use self::NodeLabels::*;
590593
use super::{Id, Labeller, Nodes, Edges, GraphWalk, render};
591594
use super::LabelText::{self, LabelStr, EscStr};
592-
use std::old_io::IoResult;
595+
use std::io;
596+
use std::io::prelude::*;
593597
use std::borrow::IntoCow;
594598
use std::iter::repeat;
595599

@@ -738,10 +742,12 @@ mod tests {
738742
}
739743
}
740744

741-
fn test_input(g: LabelledGraph) -> IoResult<String> {
745+
fn test_input(g: LabelledGraph) -> io::Result<String> {
742746
let mut writer = Vec::new();
743747
render(&g, &mut writer).unwrap();
744-
(&mut &*writer).read_to_string()
748+
let mut s = String::new();
749+
try!(Read::read_to_string(&mut &*writer, &mut s));
750+
Ok(s)
745751
}
746752

747753
// All of the tests use raw-strings as the format for the expected outputs,
@@ -853,9 +859,10 @@ r#"digraph hasse_diagram {
853859
edge(1, 3, ";"), edge(2, 3, ";" )));
854860

855861
render(&g, &mut writer).unwrap();
856-
let r = (&mut &*writer).read_to_string();
862+
let mut r = String::new();
863+
Read::read_to_string(&mut &*writer, &mut r).unwrap();
857864

858-
assert_eq!(r.unwrap(),
865+
assert_eq!(r,
859866
r#"digraph syntax_tree {
860867
N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"];
861868
N1[label="branch1"];

src/liblog/lib.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,14 @@
174174
#![feature(box_syntax)]
175175
#![feature(int_uint)]
176176
#![feature(core)]
177-
#![feature(old_io)]
178177
#![feature(std_misc)]
178+
#![feature(io)]
179179

180180
use std::boxed;
181181
use std::cell::RefCell;
182182
use std::fmt;
183-
use std::old_io::LineBufferedWriter;
184-
use std::old_io;
183+
use std::io::{self, Stderr};
184+
use std::io::prelude::*;
185185
use std::mem;
186186
use std::env;
187187
use std::ptr;
@@ -237,9 +237,7 @@ pub trait Logger {
237237
fn log(&mut self, record: &LogRecord);
238238
}
239239

240-
struct DefaultLogger {
241-
handle: LineBufferedWriter<old_io::stdio::StdWriter>,
242-
}
240+
struct DefaultLogger { handle: Stderr }
243241

244242
/// Wraps the log level with fmt implementations.
245243
#[derive(Copy, PartialEq, PartialOrd, Debug)]
@@ -300,7 +298,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: fmt::Arguments) {
300298
let mut logger = LOCAL_LOGGER.with(|s| {
301299
s.borrow_mut().take()
302300
}).unwrap_or_else(|| {
303-
box DefaultLogger { handle: old_io::stderr() } as Box<Logger + Send>
301+
box DefaultLogger { handle: io::stderr() } as Box<Logger + Send>
304302
});
305303
logger.log(&LogRecord {
306304
level: LogLevel(level),

0 commit comments

Comments
 (0)