Skip to content

Commit

Permalink
Auto merge of #23292 - alexcrichton:stabilize-io, r=aturon
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
bors committed Mar 13, 2015
2 parents 9eb69ab + 981bf5f commit 3e4be02
Show file tree
Hide file tree
Showing 69 changed files with 820 additions and 898 deletions.
8 changes: 5 additions & 3 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![feature(std_misc)]
#![feature(test)]
#![feature(core)]
#![feature(io)]
#![feature(net)]
#![feature(path_ext)]

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

use std::env;
use std::fs;
use std::old_io;
use std::path::{Path, PathBuf};
use std::thunk::Thunk;
use getopts::{optopt, optflag, reqopt};
Expand Down Expand Up @@ -246,7 +244,11 @@ pub fn run_tests(config: &Config) {
// sadly osx needs some file descriptor limits raised for running tests in
// parallel (especially when we have lots and lots of child processes).
// For context, see #8904
old_io::test::raise_fd_limit();
#[allow(deprecated)]
fn raise_fd_limit() {
std::old_io::test::raise_fd_limit();
}
raise_fd_limit();
// Prevent issue #21352 UAC blocking .exe containing 'patch' etc. on Windows
// If #11207 is resolved (adding manifest to .exe) this becomes unnecessary
env::set_var("__COMPAT_LAYER", "RunAsInvoker");
Expand Down
7 changes: 5 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use std::io::BufReader;
use std::io::prelude::*;
use std::iter::repeat;
use std::net::TcpStream;
use std::old_io::timer;
use std::path::{Path, PathBuf};
use std::process::{Command, Output, ExitStatus};
use std::str;
Expand Down Expand Up @@ -452,7 +451,11 @@ fn run_debuginfo_gdb_test(config: &Config, props: &TestProps, testfile: &Path) {
.expect(&format!("failed to exec `{:?}`", config.adb_path));
loop {
//waiting 1 second for gdbserver start
timer::sleep(Duration::milliseconds(1000));
#[allow(deprecated)]
fn sleep() {
::std::old_io::timer::sleep(Duration::milliseconds(1000));
}
sleep();
if TcpStream::connect("127.0.0.1:5039").is_ok() {
break
}
Expand Down
63 changes: 35 additions & 28 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@
//!
//! ```rust
//! use std::borrow::IntoCow;
//! use std::io::Write;
//! use graphviz as dot;
//!
//! type Nd = int;
//! type Ed = (int,int);
//! struct Edges(Vec<Ed>);
//!
//! pub fn render_to<W:Writer>(output: &mut W) {
//! pub fn render_to<W: Write>(output: &mut W) {
//! let edges = Edges(vec!((0,1), (0,2), (1,3), (2,3), (3,4), (4,4)));
//! dot::render(&edges, output).unwrap()
//! }
Expand Down Expand Up @@ -94,10 +95,10 @@
//! ```
//!
//! ```no_run
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
//! pub fn main() {
//! use std::old_io::File;
//! let mut f = File::create(&Path::new("example1.dot"));
//! use std::fs::File;
//! let mut f = File::create("example1.dot").unwrap();
//! render_to(&mut f)
//! }
//! ```
Expand Down Expand Up @@ -148,13 +149,14 @@
//!
//! ```rust
//! use std::borrow::IntoCow;
//! use std::io::Write;
//! use graphviz as dot;
//!
//! type Nd = uint;
//! type Ed<'a> = &'a (uint, uint);
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
//!
//! pub fn render_to<W:Writer>(output: &mut W) {
//! pub fn render_to<W: Write>(output: &mut W) {
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
//! let graph = Graph { nodes: nodes, edges: edges };
Expand Down Expand Up @@ -186,10 +188,10 @@
//! ```
//!
//! ```no_run
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
//! pub fn main() {
//! use std::old_io::File;
//! let mut f = File::create(&Path::new("example2.dot"));
//! use std::fs::File;
//! let mut f = File::create("example2.dot").unwrap();
//! render_to(&mut f)
//! }
//! ```
Expand All @@ -204,13 +206,14 @@
//!
//! ```rust
//! use std::borrow::IntoCow;
//! use std::io::Write;
//! use graphviz as dot;
//!
//! type Nd<'a> = (uint, &'a str);
//! type Ed<'a> = (Nd<'a>, Nd<'a>);
//! struct Graph { nodes: Vec<&'static str>, edges: Vec<(uint,uint)> }
//!
//! pub fn render_to<W:Writer>(output: &mut W) {
//! pub fn render_to<W: Write>(output: &mut W) {
//! let nodes = vec!("{x,y}","{x}","{y}","{}");
//! let edges = vec!((0,1), (0,2), (1,3), (2,3));
//! let graph = Graph { nodes: nodes, edges: edges };
Expand Down Expand Up @@ -250,10 +253,10 @@
//! ```
//!
//! ```no_run
//! # pub fn render_to<W:Writer>(output: &mut W) { unimplemented!() }
//! # pub fn render_to<W:std::io::Write>(output: &mut W) { unimplemented!() }
//! pub fn main() {
//! use std::old_io::File;
//! let mut f = File::create(&Path::new("example3.dot"));
//! use std::fs::File;
//! let mut f = File::create("example3.dot").unwrap();
//! render_to(&mut f)
//! }
//! ```
Expand All @@ -277,12 +280,12 @@
html_root_url = "http://doc.rust-lang.org/nightly/")]
#![feature(int_uint)]
#![feature(collections)]
#![feature(old_io)]

use self::LabelText::*;

use std::borrow::{IntoCow, Cow};
use std::old_io;
use std::io::prelude::*;
use std::io;

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

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

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

fn indent<W:Writer>(w: &mut W) -> old_io::IoResult<()> {
w.write_str(" ")
fn indent<W:Write>(w: &mut W) -> io::Result<()> {
w.write_all(b" ")
}

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

Expand Down Expand Up @@ -738,10 +742,12 @@ mod tests {
}
}

fn test_input(g: LabelledGraph) -> IoResult<String> {
fn test_input(g: LabelledGraph) -> io::Result<String> {
let mut writer = Vec::new();
render(&g, &mut writer).unwrap();
(&mut &*writer).read_to_string()
let mut s = String::new();
try!(Read::read_to_string(&mut &*writer, &mut s));
Ok(s)
}

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

render(&g, &mut writer).unwrap();
let r = (&mut &*writer).read_to_string();
let mut r = String::new();
Read::read_to_string(&mut &*writer, &mut r).unwrap();

assert_eq!(r.unwrap(),
assert_eq!(r,
r#"digraph syntax_tree {
N0[label="if test {\l branch1\l} else {\l branch2\l}\lafterward\l"];
N1[label="branch1"];
Expand Down
12 changes: 5 additions & 7 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,14 @@
#![feature(box_syntax)]
#![feature(int_uint)]
#![feature(core)]
#![feature(old_io)]
#![feature(std_misc)]
#![feature(io)]

use std::boxed;
use std::cell::RefCell;
use std::fmt;
use std::old_io::LineBufferedWriter;
use std::old_io;
use std::io::{self, Stderr};
use std::io::prelude::*;
use std::mem;
use std::env;
use std::ptr;
Expand Down Expand Up @@ -237,9 +237,7 @@ pub trait Logger {
fn log(&mut self, record: &LogRecord);
}

struct DefaultLogger {
handle: LineBufferedWriter<old_io::stdio::StdWriter>,
}
struct DefaultLogger { handle: Stderr }

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

0 comments on commit 3e4be02

Please sign in to comment.