std: Rename Writer::write to Writer::write_all

In preparation for upcoming changes to the `Writer` trait (soon to be called
`Write`) this commit renames the current `write` method to `write_all` to match
the semantics of the upcoming `write_all` method. The `write` method will be
repurposed to return a `usize` indicating how much data was written which
differs from the current `write` semantics. In order to head off as much
unintended breakage as possible, the method is being deprecated now in favor of
a new name.

[breaking-change]
This commit is contained in:
Alex Crichton 2015-01-23 10:46:14 -08:00
parent 3a07f859b8
commit 5d836cdf86
41 changed files with 229 additions and 226 deletions

View File

@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
match cmd.spawn() { match cmd.spawn() {
Ok(mut process) => { Ok(mut process) => {
for input in input.iter() { for input in input.iter() {
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap(); process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
} }
let ProcessOutput { status, output, error } = let ProcessOutput { status, output, error } =
process.wait_with_output().unwrap(); process.wait_with_output().unwrap();
@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
match cmd.spawn() { match cmd.spawn() {
Ok(mut process) => { Ok(mut process) => {
for input in input.iter() { for input in input.iter() {
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap(); process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
} }
Some(process) Some(process)

View File

@ -1401,7 +1401,7 @@ fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &Config, testfile: &Path, fn dump_output_file(config: &Config, testfile: &Path,
out: &str, extension: &str) { out: &str, extension: &str) {
let outfile = make_out_name(config, testfile, extension); let outfile = make_out_name(config, testfile, extension);
File::create(&outfile).write(out.as_bytes()).unwrap(); File::create(&outfile).write_all(out.as_bytes()).unwrap();
} }
fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path { fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path {

View File

@ -170,7 +170,7 @@ mod u32 {
use test::Bencher; use test::Bencher;
use core::fmt::radix; use core::fmt::radix;
use std::rand::{weak_rng, Rng}; use std::rand::{weak_rng, Rng};
use std::io::util::NullWriter; use std::old_io::util::NullWriter;
#[bench] #[bench]
fn format_bin(b: &mut Bencher) { fn format_bin(b: &mut Bencher) {
@ -213,7 +213,7 @@ mod i32 {
use test::Bencher; use test::Bencher;
use core::fmt::radix; use core::fmt::radix;
use std::rand::{weak_rng, Rng}; use std::rand::{weak_rng, Rng};
use std::io::util::NullWriter; use std::old_io::util::NullWriter;
#[bench] #[bench]
fn format_bin(b: &mut Bencher) { fn format_bin(b: &mut Bencher) {

View File

@ -80,7 +80,7 @@ impl SeekableMemWriter {
impl Writer for SeekableMemWriter { impl Writer for SeekableMemWriter {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
if self.pos == self.buf.len() { if self.pos == self.buf.len() {
self.buf.push_all(buf) self.buf.push_all(buf)
} else { } else {

View File

@ -708,11 +708,11 @@ pub mod writer {
fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult { fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
match size { match size {
1u => w.write(&[0x80u8 | (n as u8)]), 1u => w.write_all(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]), 2u => w.write_all(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8, 3u => w.write_all(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
n as u8]), n as u8]),
4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8, 4u => w.write_all(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
(n >> 8_u) as u8, n as u8]), (n >> 8_u) as u8, n as u8]),
_ => Err(old_io::IoError { _ => Err(old_io::IoError {
kind: old_io::OtherIoError, kind: old_io::OtherIoError,
@ -760,7 +760,7 @@ pub mod writer {
// Write a placeholder four-byte size. // Write a placeholder four-byte size.
self.size_positions.push(try!(self.writer.tell()) as uint); self.size_positions.push(try!(self.writer.tell()) as uint);
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8]; let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
self.writer.write(zeroes) self.writer.write_all(zeroes)
} }
pub fn end_tag(&mut self) -> EncodeResult { pub fn end_tag(&mut self) -> EncodeResult {
@ -786,7 +786,7 @@ pub mod writer {
pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) -> EncodeResult { pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) -> EncodeResult {
try!(write_vuint(self.writer, tag_id)); try!(write_vuint(self.writer, tag_id));
try!(write_vuint(self.writer, b.len())); try!(write_vuint(self.writer, b.len()));
self.writer.write(b) self.writer.write_all(b)
} }
pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) -> EncodeResult { pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) -> EncodeResult {
@ -839,12 +839,12 @@ pub mod writer {
pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult { pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult {
debug!("Write {:?} bytes", b.len()); debug!("Write {:?} bytes", b.len());
self.writer.write(b) self.writer.write_all(b)
} }
pub fn wr_str(&mut self, s: &str) -> EncodeResult { pub fn wr_str(&mut self, s: &str) -> EncodeResult {
debug!("Write str: {:?}", s); debug!("Write str: {:?}", s);
self.writer.write(s.as_bytes()) self.writer.write_all(s.as_bytes())
} }
} }

View File

@ -122,7 +122,7 @@ fn encode_trait_ref<'a, 'tcx>(rbml_w: &mut Encoder,
// Item info table encoding // Item info table encoding
fn encode_family(rbml_w: &mut Encoder, c: char) { fn encode_family(rbml_w: &mut Encoder, c: char) {
rbml_w.start_tag(tag_items_data_item_family); rbml_w.start_tag(tag_items_data_item_family);
rbml_w.writer.write(&[c as u8]); rbml_w.writer.write_all(&[c as u8]);
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -149,7 +149,7 @@ fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) { fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) {
rbml_w.start_tag(tag_items_data_item_variant); rbml_w.start_tag(tag_items_data_item_variant);
let s = def_to_string(vid); let s = def_to_string(vid);
rbml_w.writer.write(s.as_bytes()); rbml_w.writer.write_all(s.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.start_tag(tag_mod_child); rbml_w.start_tag(tag_mod_child);
@ -259,7 +259,7 @@ fn encode_symbol(ecx: &EncodeContext,
match ecx.item_symbols.borrow().get(&id) { match ecx.item_symbols.borrow().get(&id) {
Some(x) => { Some(x) => {
debug!("encode_symbol(id={}, str={})", id, *x); debug!("encode_symbol(id={}, str={})", id, *x);
rbml_w.writer.write(x.as_bytes()); rbml_w.writer.write_all(x.as_bytes());
} }
None => { None => {
ecx.diag.handler().bug( ecx.diag.handler().bug(
@ -274,14 +274,14 @@ fn encode_disr_val(_: &EncodeContext,
disr_val: ty::Disr) { disr_val: ty::Disr) {
rbml_w.start_tag(tag_disr_val); rbml_w.start_tag(tag_disr_val);
let s = disr_val.to_string(); let s = disr_val.to_string();
rbml_w.writer.write(s.as_bytes()); rbml_w.writer.write_all(s.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) { fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
rbml_w.start_tag(tag_items_data_parent_item); rbml_w.start_tag(tag_items_data_parent_item);
let s = def_to_string(id); let s = def_to_string(id);
rbml_w.writer.write(s.as_bytes()); rbml_w.writer.write_all(s.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -299,7 +299,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
encode_def_id(rbml_w, f.id); encode_def_id(rbml_w, f.id);
rbml_w.start_tag(tag_item_field_origin); rbml_w.start_tag(tag_item_field_origin);
let s = def_to_string(origin); let s = def_to_string(origin);
rbml_w.writer.write(s.as_bytes()); rbml_w.writer.write_all(s.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -636,17 +636,17 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
// Encode the base self type. // Encode the base self type.
match *explicit_self { match *explicit_self {
ty::StaticExplicitSelfCategory => { ty::StaticExplicitSelfCategory => {
rbml_w.writer.write(&[ 's' as u8 ]); rbml_w.writer.write_all(&[ 's' as u8 ]);
} }
ty::ByValueExplicitSelfCategory => { ty::ByValueExplicitSelfCategory => {
rbml_w.writer.write(&[ 'v' as u8 ]); rbml_w.writer.write_all(&[ 'v' as u8 ]);
} }
ty::ByBoxExplicitSelfCategory => { ty::ByBoxExplicitSelfCategory => {
rbml_w.writer.write(&[ '~' as u8 ]); rbml_w.writer.write_all(&[ '~' as u8 ]);
} }
ty::ByReferenceExplicitSelfCategory(_, m) => { ty::ByReferenceExplicitSelfCategory(_, m) => {
// FIXME(#4846) encode custom lifetime // FIXME(#4846) encode custom lifetime
rbml_w.writer.write(&['&' as u8]); rbml_w.writer.write_all(&['&' as u8]);
encode_mutability(rbml_w, m); encode_mutability(rbml_w, m);
} }
} }
@ -656,21 +656,21 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
fn encode_mutability(rbml_w: &mut Encoder, fn encode_mutability(rbml_w: &mut Encoder,
m: ast::Mutability) { m: ast::Mutability) {
match m { match m {
ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); } ast::MutImmutable => { rbml_w.writer.write_all(&[ 'i' as u8 ]); }
ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); } ast::MutMutable => { rbml_w.writer.write_all(&[ 'm' as u8 ]); }
} }
} }
} }
fn encode_item_sort(rbml_w: &mut Encoder, sort: char) { fn encode_item_sort(rbml_w: &mut Encoder, sort: char) {
rbml_w.start_tag(tag_item_trait_item_sort); rbml_w.start_tag(tag_item_trait_item_sort);
rbml_w.writer.write(&[ sort as u8 ]); rbml_w.writer.write_all(&[ sort as u8 ]);
rbml_w.end_tag(); rbml_w.end_tag();
} }
fn encode_parent_sort(rbml_w: &mut Encoder, sort: char) { fn encode_parent_sort(rbml_w: &mut Encoder, sort: char) {
rbml_w.start_tag(tag_item_trait_parent_sort); rbml_w.start_tag(tag_item_trait_parent_sort);
rbml_w.writer.write(&[ sort as u8 ]); rbml_w.writer.write_all(&[ sort as u8 ]);
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -679,7 +679,7 @@ fn encode_provided_source(rbml_w: &mut Encoder,
for source in source_opt.iter() { for source in source_opt.iter() {
rbml_w.start_tag(tag_item_method_provided_source); rbml_w.start_tag(tag_item_method_provided_source);
let s = def_to_string(*source); let s = def_to_string(*source);
rbml_w.writer.write(s.as_bytes()); rbml_w.writer.write_all(s.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
} }
@ -926,7 +926,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
rbml_w.start_tag(tag_method_argument_name); rbml_w.start_tag(tag_method_argument_name);
if let ast::PatIdent(_, ref path1, _) = arg.pat.node { if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
let name = token::get_ident(path1.node); let name = token::get_ident(path1.node);
rbml_w.writer.write(name.get().as_bytes()); rbml_w.writer.write_all(name.get().as_bytes());
} }
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -1646,7 +1646,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::MetaWord(ref name) => { ast::MetaWord(ref name) => {
rbml_w.start_tag(tag_meta_item_word); rbml_w.start_tag(tag_meta_item_word);
rbml_w.start_tag(tag_meta_item_name); rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes()); rbml_w.writer.write_all(name.get().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -1655,10 +1655,10 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::LitStr(ref value, _) => { ast::LitStr(ref value, _) => {
rbml_w.start_tag(tag_meta_item_name_value); rbml_w.start_tag(tag_meta_item_name_value);
rbml_w.start_tag(tag_meta_item_name); rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes()); rbml_w.writer.write_all(name.get().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.start_tag(tag_meta_item_value); rbml_w.start_tag(tag_meta_item_value);
rbml_w.writer.write(value.get().as_bytes()); rbml_w.writer.write_all(value.get().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -1668,7 +1668,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::MetaList(ref name, ref items) => { ast::MetaList(ref name, ref items) => {
rbml_w.start_tag(tag_meta_item_list); rbml_w.start_tag(tag_meta_item_list);
rbml_w.start_tag(tag_meta_item_name); rbml_w.start_tag(tag_meta_item_name);
rbml_w.writer.write(name.get().as_bytes()); rbml_w.writer.write_all(name.get().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
for inner_item in items.iter() { for inner_item in items.iter() {
encode_meta_item(rbml_w, &**inner_item); encode_meta_item(rbml_w, &**inner_item);
@ -1800,7 +1800,7 @@ fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) {
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.start_tag(tag_native_libraries_name); rbml_w.start_tag(tag_native_libraries_name);
rbml_w.writer.write(lib.as_bytes()); rbml_w.writer.write_all(lib.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.end_tag(); rbml_w.end_tag();
@ -1975,29 +1975,29 @@ fn encode_crate_dep(rbml_w: &mut Encoder,
dep: decoder::CrateDep) { dep: decoder::CrateDep) {
rbml_w.start_tag(tag_crate_dep); rbml_w.start_tag(tag_crate_dep);
rbml_w.start_tag(tag_crate_dep_crate_name); rbml_w.start_tag(tag_crate_dep_crate_name);
rbml_w.writer.write(dep.name.as_bytes()); rbml_w.writer.write_all(dep.name.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.start_tag(tag_crate_dep_hash); rbml_w.start_tag(tag_crate_dep_hash);
rbml_w.writer.write(dep.hash.as_str().as_bytes()); rbml_w.writer.write_all(dep.hash.as_str().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
rbml_w.end_tag(); rbml_w.end_tag();
} }
fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) { fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) {
rbml_w.start_tag(tag_crate_hash); rbml_w.start_tag(tag_crate_hash);
rbml_w.writer.write(hash.as_str().as_bytes()); rbml_w.writer.write_all(hash.as_str().as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) { fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) {
rbml_w.start_tag(tag_crate_crate_name); rbml_w.start_tag(tag_crate_crate_name);
rbml_w.writer.write(crate_name.as_bytes()); rbml_w.writer.write_all(crate_name.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) { fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) {
rbml_w.start_tag(tag_crate_triple); rbml_w.start_tag(tag_crate_triple);
rbml_w.writer.write(triple.as_bytes()); rbml_w.writer.write_all(triple.as_bytes());
rbml_w.end_tag(); rbml_w.end_tag();
} }
@ -2011,7 +2011,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
cstore::RequireStatic => "s", cstore::RequireStatic => "s",
})).to_string()) })).to_string())
}).collect::<Vec<String>>(); }).collect::<Vec<String>>();
rbml_w.writer.write(s.connect(",").as_bytes()); rbml_w.writer.write_all(s.connect(",").as_bytes());
} }
None => {} None => {}
} }

View File

@ -51,7 +51,7 @@ pub type abbrev_map<'tcx> = RefCell<FnvHashMap<Ty<'tcx>, ty_abbrev>>;
pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) { pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
match cx.abbrevs.borrow_mut().get(&t) { match cx.abbrevs.borrow_mut().get(&t) {
Some(a) => { w.write(a.s.as_bytes()); return; } Some(a) => { w.write_all(a.s.as_bytes()); return; }
None => {} None => {}
} }
let pos = w.tell().unwrap(); let pos = w.tell().unwrap();

View File

@ -586,8 +586,7 @@ fn link_rlib<'a>(sess: &'a Session,
// the same filename for metadata (stomping over one another) // the same filename for metadata (stomping over one another)
let tmpdir = TempDir::new("rustc").ok().expect("needs a temp dir"); let tmpdir = TempDir::new("rustc").ok().expect("needs a temp dir");
let metadata = tmpdir.path().join(METADATA_FILENAME); let metadata = tmpdir.path().join(METADATA_FILENAME);
match fs::File::create(&metadata).write(&trans.metadata match fs::File::create(&metadata).write_all(&trans.metadata[]) {
[]) {
Ok(..) => {} Ok(..) => {}
Err(e) => { Err(e) => {
sess.err(&format!("failed to write {}: {}", sess.err(&format!("failed to write {}: {}",
@ -674,10 +673,10 @@ fn write_rlib_bytecode_object_v1<T: Writer>(writer: &mut T,
-> ::std::old_io::IoResult<()> { -> ::std::old_io::IoResult<()> {
let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64; let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64;
try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) }; try! { writer.write_all(RLIB_BYTECODE_OBJECT_MAGIC) };
try! { writer.write_le_u32(1) }; try! { writer.write_le_u32(1) };
try! { writer.write_le_u64(bc_data_deflated_size) }; try! { writer.write_le_u64(bc_data_deflated_size) };
try! { writer.write(&bc_data_deflated[]) }; try! { writer.write_all(&bc_data_deflated[]) };
let number_of_bytes_written_so_far = let number_of_bytes_written_so_far =
RLIB_BYTECODE_OBJECT_MAGIC.len() + // magic id RLIB_BYTECODE_OBJECT_MAGIC.len() + // magic id

View File

@ -626,7 +626,7 @@ fn render_sources(cx: &mut Context,
/// Writes the entire contents of a string to a destination, not attempting to /// Writes the entire contents of a string to a destination, not attempting to
/// catch any errors. /// catch any errors.
fn write(dst: Path, contents: &[u8]) -> old_io::IoResult<()> { fn write(dst: Path, contents: &[u8]) -> old_io::IoResult<()> {
File::create(&dst).write(contents) File::create(&dst).write_all(contents)
} }
/// Makes a directory on the filesystem, failing the task if an error occurs and /// Makes a directory on the filesystem, failing the task if an error occurs and

View File

@ -27,7 +27,7 @@ thread_local! {
} }
impl Writer for Stdio { impl Writer for Stdio {
fn write(&mut self, bytes: &[u8]) -> IoResult<()> { fn write_all(&mut self, bytes: &[u8]) -> IoResult<()> {
let _ = self.write_bytes(bytes); let _ = self.write_bytes(bytes);
Ok(()) Ok(())
} }

View File

@ -184,7 +184,7 @@ impl<W: Writer> BufferedWriter<W> {
fn flush_buf(&mut self) -> IoResult<()> { fn flush_buf(&mut self) -> IoResult<()> {
if self.pos != 0 { if self.pos != 0 {
let ret = self.inner.as_mut().unwrap().write(&self.buf[..self.pos]); let ret = self.inner.as_mut().unwrap().write_all(&self.buf[..self.pos]);
self.pos = 0; self.pos = 0;
ret ret
} else { } else {
@ -213,13 +213,13 @@ impl<W: Writer> BufferedWriter<W> {
} }
impl<W: Writer> Writer for BufferedWriter<W> { impl<W: Writer> Writer for BufferedWriter<W> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
if self.pos + buf.len() > self.buf.len() { if self.pos + buf.len() > self.buf.len() {
try!(self.flush_buf()); try!(self.flush_buf());
} }
if buf.len() > self.buf.len() { if buf.len() > self.buf.len() {
self.inner.as_mut().unwrap().write(buf) self.inner.as_mut().unwrap().write_all(buf)
} else { } else {
let dst = &mut self.buf[self.pos..]; let dst = &mut self.buf[self.pos..];
slice::bytes::copy_memory(dst, buf); slice::bytes::copy_memory(dst, buf);
@ -281,15 +281,15 @@ impl<W: Writer> LineBufferedWriter<W> {
} }
impl<W: Writer> Writer for LineBufferedWriter<W> { impl<W: Writer> Writer for LineBufferedWriter<W> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
match buf.iter().rposition(|&b| b == b'\n') { match buf.iter().rposition(|&b| b == b'\n') {
Some(i) => { Some(i) => {
try!(self.inner.write(&buf[..i + 1])); try!(self.inner.write_all(&buf[..i + 1]));
try!(self.inner.flush()); try!(self.inner.flush());
try!(self.inner.write(&buf[i + 1..])); try!(self.inner.write_all(&buf[i + 1..]));
Ok(()) Ok(())
} }
None => self.inner.write(buf), None => self.inner.write_all(buf),
} }
} }
@ -329,7 +329,7 @@ impl<W: Reader> Reader for InternalBufferedWriter<W> {
/// let file = File::open(&Path::new("message.txt")); /// let file = File::open(&Path::new("message.txt"));
/// let mut stream = BufferedStream::new(file); /// let mut stream = BufferedStream::new(file);
/// ///
/// stream.write("hello, world".as_bytes()); /// stream.write_all("hello, world".as_bytes());
/// stream.flush(); /// stream.flush();
/// ///
/// let mut buf = [0; 100]; /// let mut buf = [0; 100];
@ -412,8 +412,8 @@ impl<S: Stream> Reader for BufferedStream<S> {
} }
impl<S: Stream> Writer for BufferedStream<S> { impl<S: Stream> Writer for BufferedStream<S> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.inner.inner.get_mut().write(buf) self.inner.inner.get_mut().write_all(buf)
} }
fn flush(&mut self) -> IoResult<()> { fn flush(&mut self) -> IoResult<()> {
self.inner.inner.get_mut().flush() self.inner.inner.get_mut().flush()
@ -443,7 +443,7 @@ mod test {
} }
impl Writer for NullStream { impl Writer for NullStream {
fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) } fn write_all(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) }
} }
/// A dummy reader intended at testing short-reads propagation. /// A dummy reader intended at testing short-reads propagation.
@ -503,34 +503,34 @@ mod test {
let inner = Vec::new(); let inner = Vec::new();
let mut writer = BufferedWriter::with_capacity(2, inner); let mut writer = BufferedWriter::with_capacity(2, inner);
writer.write(&[0, 1]).unwrap(); writer.write_all(&[0, 1]).unwrap();
let b: &[_] = &[]; let b: &[_] = &[];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.write(&[2]).unwrap(); writer.write_all(&[2]).unwrap();
let b: &[_] = &[0, 1]; let b: &[_] = &[0, 1];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.write(&[3]).unwrap(); writer.write_all(&[3]).unwrap();
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.flush().unwrap(); writer.flush().unwrap();
let a: &[_] = &[0, 1, 2, 3]; let a: &[_] = &[0, 1, 2, 3];
assert_eq!(a, &writer.get_ref()[]); assert_eq!(a, &writer.get_ref()[]);
writer.write(&[4]).unwrap(); writer.write_all(&[4]).unwrap();
writer.write(&[5]).unwrap(); writer.write_all(&[5]).unwrap();
assert_eq!(a, &writer.get_ref()[]); assert_eq!(a, &writer.get_ref()[]);
writer.write(&[6]).unwrap(); writer.write_all(&[6]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5]; let a: &[_] = &[0, 1, 2, 3, 4, 5];
assert_eq!(a, &writer.get_ref()[]); assert_eq!(a, &writer.get_ref()[]);
writer.write(&[7, 8]).unwrap(); writer.write_all(&[7, 8]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6]; let a: &[_] = &[0, 1, 2, 3, 4, 5, 6];
assert_eq!(a, &writer.get_ref()[]); assert_eq!(a, &writer.get_ref()[]);
writer.write(&[9, 10, 11]).unwrap(); writer.write_all(&[9, 10, 11]).unwrap();
let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; let a: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
assert_eq!(a, &writer.get_ref()[]); assert_eq!(a, &writer.get_ref()[]);
@ -541,7 +541,7 @@ mod test {
#[test] #[test]
fn test_buffered_writer_inner_flushes() { fn test_buffered_writer_inner_flushes() {
let mut w = BufferedWriter::with_capacity(3, Vec::new()); let mut w = BufferedWriter::with_capacity(3, Vec::new());
w.write(&[0, 1]).unwrap(); w.write_all(&[0, 1]).unwrap();
let a: &[_] = &[]; let a: &[_] = &[];
assert_eq!(a, &w.get_ref()[]); assert_eq!(a, &w.get_ref()[]);
let w = w.into_inner(); let w = w.into_inner();
@ -556,7 +556,7 @@ mod test {
struct S; struct S;
impl old_io::Writer for S { impl old_io::Writer for S {
fn write(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) } fn write_all(&mut self, _: &[u8]) -> old_io::IoResult<()> { Ok(()) }
} }
impl old_io::Reader for S { impl old_io::Reader for S {
@ -568,7 +568,7 @@ mod test {
let mut stream = BufferedStream::new(S); let mut stream = BufferedStream::new(S);
let mut buf = []; let mut buf = [];
assert!(stream.read(&mut buf).is_err()); assert!(stream.read(&mut buf).is_err());
stream.write(&buf).unwrap(); stream.write_all(&buf).unwrap();
stream.flush().unwrap(); stream.flush().unwrap();
} }
@ -586,21 +586,21 @@ mod test {
#[test] #[test]
fn test_line_buffer() { fn test_line_buffer() {
let mut writer = LineBufferedWriter::new(Vec::new()); let mut writer = LineBufferedWriter::new(Vec::new());
writer.write(&[0]).unwrap(); writer.write_all(&[0]).unwrap();
let b: &[_] = &[]; let b: &[_] = &[];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.write(&[1]).unwrap(); writer.write_all(&[1]).unwrap();
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.flush().unwrap(); writer.flush().unwrap();
let b: &[_] = &[0, 1]; let b: &[_] = &[0, 1];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.write(&[0, b'\n', 1, b'\n', 2]).unwrap(); writer.write_all(&[0, b'\n', 1, b'\n', 2]).unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n']; let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n'];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.flush().unwrap(); writer.flush().unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2]; let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
writer.write(&[3, b'\n']).unwrap(); writer.write_all(&[3, b'\n']).unwrap();
let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n']; let b: &[_] = &[0, 1, 0, b'\n', 1, b'\n', 2, 3, b'\n'];
assert_eq!(&writer.get_ref()[], b); assert_eq!(&writer.get_ref()[], b);
} }
@ -663,7 +663,7 @@ mod test {
struct FailFlushWriter; struct FailFlushWriter;
impl Writer for FailFlushWriter { impl Writer for FailFlushWriter {
fn write(&mut self, _buf: &[u8]) -> IoResult<()> { Ok(()) } fn write_all(&mut self, _buf: &[u8]) -> IoResult<()> { Ok(()) }
fn flush(&mut self) -> IoResult<()> { Err(old_io::standard_error(EndOfFile)) } fn flush(&mut self) -> IoResult<()> { Err(old_io::standard_error(EndOfFile)) }
} }

View File

@ -142,7 +142,7 @@ impl Clone for ChanWriter {
} }
impl Writer for ChanWriter { impl Writer for ChanWriter {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.tx.send(buf.to_vec()).map_err(|_| { self.tx.send(buf.to_vec()).map_err(|_| {
old_io::IoError { old_io::IoError {
kind: old_io::BrokenPipe, kind: old_io::BrokenPipe,

View File

@ -719,7 +719,7 @@ impl Reader for File {
} }
impl Writer for File { impl Writer for File {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.fd.write(buf) self.fd.write(buf)
.update_err("couldn't write to file", .update_err("couldn't write to file",
|e| format!("{}; path={}", e, self.path.display())) |e| format!("{}; path={}", e, self.path.display()))

View File

@ -43,7 +43,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64>
impl Writer for Vec<u8> { impl Writer for Vec<u8> {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.push_all(buf); self.push_all(buf);
Ok(()) Ok(())
} }
@ -99,7 +99,7 @@ impl MemWriter {
impl Writer for MemWriter { impl Writer for MemWriter {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.buf.push_all(buf); self.buf.push_all(buf);
Ok(()) Ok(())
} }
@ -269,7 +269,7 @@ impl<'a> BufWriter<'a> {
impl<'a> Writer for BufWriter<'a> { impl<'a> Writer for BufWriter<'a> {
#[inline] #[inline]
fn write(&mut self, src: &[u8]) -> IoResult<()> { fn write_all(&mut self, src: &[u8]) -> IoResult<()> {
let dst = &mut self.buf[self.pos..]; let dst = &mut self.buf[self.pos..];
let dst_len = dst.len(); let dst_len = dst.len();

View File

@ -70,7 +70,7 @@
//! use std::old_io::File; //! use std::old_io::File;
//! //!
//! let mut file = File::create(&Path::new("message.txt")); //! let mut file = File::create(&Path::new("message.txt"));
//! file.write(b"hello, file!\n"); //! file.write_all(b"hello, file!\n");
//! # drop(file); //! # drop(file);
//! # ::std::old_io::fs::unlink(&Path::new("message.txt")); //! # ::std::old_io::fs::unlink(&Path::new("message.txt"));
//! ``` //! ```
@ -110,7 +110,7 @@
//! # // just stop it running (#11576) //! # // just stop it running (#11576)
//! # if false { //! # if false {
//! let mut socket = TcpStream::connect("127.0.0.1:8080").unwrap(); //! let mut socket = TcpStream::connect("127.0.0.1:8080").unwrap();
//! socket.write(b"GET / HTTP/1.0\n\n"); //! socket.write_all(b"GET / HTTP/1.0\n\n");
//! let response = socket.read_to_end(); //! let response = socket.read_to_end();
//! # } //! # }
//! ``` //! ```
@ -174,7 +174,7 @@
//! to be 'unwrapped' before use. //! to be 'unwrapped' before use.
//! //!
//! These features combine in the API to allow for expressions like //! These features combine in the API to allow for expressions like
//! `File::create(&Path::new("diary.txt")).write(b"Met a girl.\n")` //! `File::create(&Path::new("diary.txt")).write_all(b"Met a girl.\n")`
//! without having to worry about whether "diary.txt" exists or whether //! without having to worry about whether "diary.txt" exists or whether
//! the write succeeds. As written, if either `new` or `write_line` //! the write succeeds. As written, if either `new` or `write_line`
//! encounters an error then the result of the entire expression will //! encounters an error then the result of the entire expression will
@ -186,7 +186,7 @@
//! # #![allow(unused_must_use)] //! # #![allow(unused_must_use)]
//! use std::old_io::File; //! use std::old_io::File;
//! //!
//! match File::create(&Path::new("diary.txt")).write(b"Met a girl.\n") { //! match File::create(&Path::new("diary.txt")).write_all(b"Met a girl.\n") {
//! Ok(()) => (), // succeeded //! Ok(()) => (), // succeeded
//! Err(e) => println!("failed to write to my diary: {}", e), //! Err(e) => println!("failed to write to my diary: {}", e),
//! } //! }
@ -997,7 +997,11 @@ pub trait Writer {
/// `Err`. Note that it is considered an error if the entire buffer could /// `Err`. Note that it is considered an error if the entire buffer could
/// not be written, and if an error is returned then it is unknown how much /// not be written, and if an error is returned then it is unknown how much
/// data (if any) was actually written. /// data (if any) was actually written.
fn write(&mut self, buf: &[u8]) -> IoResult<()>; fn write_all(&mut self, buf: &[u8]) -> IoResult<()>;
/// Deprecated, this method was renamed to `write_all`
#[deprecated = "renamed to `write_all`"]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.write_all(buf) }
/// Flush this output stream, ensuring that all intermediately buffered /// Flush this output stream, ensuring that all intermediately buffered
/// contents reach their destination. /// contents reach their destination.
@ -1026,7 +1030,7 @@ pub trait Writer {
impl<'a, T: ?Sized + Writer> fmt::Writer for Adaptor<'a, T> { impl<'a, T: ?Sized + Writer> fmt::Writer for Adaptor<'a, T> {
fn write_str(&mut self, s: &str) -> fmt::Result { fn write_str(&mut self, s: &str) -> fmt::Result {
match self.inner.write(s.as_bytes()) { match self.inner.write_all(s.as_bytes()) {
Ok(()) => Ok(()), Ok(()) => Ok(()),
Err(e) => { Err(e) => {
self.error = Err(e); self.error = Err(e);
@ -1052,7 +1056,7 @@ pub trait Writer {
/// converted byte-array instead. /// converted byte-array instead.
#[inline] #[inline]
fn write_str(&mut self, s: &str) -> IoResult<()> { fn write_str(&mut self, s: &str) -> IoResult<()> {
self.write(s.as_bytes()) self.write_all(s.as_bytes())
} }
/// Writes a string into this sink, and then writes a literal newline (`\n`) /// Writes a string into this sink, and then writes a literal newline (`\n`)
@ -1064,7 +1068,7 @@ pub trait Writer {
/// that the `write` method is used specifically instead. /// that the `write` method is used specifically instead.
#[inline] #[inline]
fn write_line(&mut self, s: &str) -> IoResult<()> { fn write_line(&mut self, s: &str) -> IoResult<()> {
self.write_str(s).and_then(|()| self.write(&[b'\n'])) self.write_str(s).and_then(|()| self.write_all(&[b'\n']))
} }
/// Write a single char, encoded as UTF-8. /// Write a single char, encoded as UTF-8.
@ -1072,7 +1076,7 @@ pub trait Writer {
fn write_char(&mut self, c: char) -> IoResult<()> { fn write_char(&mut self, c: char) -> IoResult<()> {
let mut buf = [0u8; 4]; let mut buf = [0u8; 4];
let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0); let n = c.encode_utf8(buf.as_mut_slice()).unwrap_or(0);
self.write(&buf[..n]) self.write_all(&buf[..n])
} }
/// Write the result of passing n through `int::to_str_bytes`. /// Write the result of passing n through `int::to_str_bytes`.
@ -1090,61 +1094,61 @@ pub trait Writer {
/// Write a little-endian uint (number of bytes depends on system). /// Write a little-endian uint (number of bytes depends on system).
#[inline] #[inline]
fn write_le_uint(&mut self, n: uint) -> IoResult<()> { fn write_le_uint(&mut self, n: uint) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, uint::BYTES, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, uint::BYTES, |v| self.write_all(v))
} }
/// Write a little-endian int (number of bytes depends on system). /// Write a little-endian int (number of bytes depends on system).
#[inline] #[inline]
fn write_le_int(&mut self, n: int) -> IoResult<()> { fn write_le_int(&mut self, n: int) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, int::BYTES, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, int::BYTES, |v| self.write_all(v))
} }
/// Write a big-endian uint (number of bytes depends on system). /// Write a big-endian uint (number of bytes depends on system).
#[inline] #[inline]
fn write_be_uint(&mut self, n: uint) -> IoResult<()> { fn write_be_uint(&mut self, n: uint) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, uint::BYTES, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, uint::BYTES, |v| self.write_all(v))
} }
/// Write a big-endian int (number of bytes depends on system). /// Write a big-endian int (number of bytes depends on system).
#[inline] #[inline]
fn write_be_int(&mut self, n: int) -> IoResult<()> { fn write_be_int(&mut self, n: int) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, int::BYTES, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, int::BYTES, |v| self.write_all(v))
} }
/// Write a big-endian u64 (8 bytes). /// Write a big-endian u64 (8 bytes).
#[inline] #[inline]
fn write_be_u64(&mut self, n: u64) -> IoResult<()> { fn write_be_u64(&mut self, n: u64) -> IoResult<()> {
extensions::u64_to_be_bytes(n, 8u, |v| self.write(v)) extensions::u64_to_be_bytes(n, 8u, |v| self.write_all(v))
} }
/// Write a big-endian u32 (4 bytes). /// Write a big-endian u32 (4 bytes).
#[inline] #[inline]
fn write_be_u32(&mut self, n: u32) -> IoResult<()> { fn write_be_u32(&mut self, n: u32) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, 4u, |v| self.write_all(v))
} }
/// Write a big-endian u16 (2 bytes). /// Write a big-endian u16 (2 bytes).
#[inline] #[inline]
fn write_be_u16(&mut self, n: u16) -> IoResult<()> { fn write_be_u16(&mut self, n: u16) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, 2u, |v| self.write_all(v))
} }
/// Write a big-endian i64 (8 bytes). /// Write a big-endian i64 (8 bytes).
#[inline] #[inline]
fn write_be_i64(&mut self, n: i64) -> IoResult<()> { fn write_be_i64(&mut self, n: i64) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, 8u, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, 8u, |v| self.write_all(v))
} }
/// Write a big-endian i32 (4 bytes). /// Write a big-endian i32 (4 bytes).
#[inline] #[inline]
fn write_be_i32(&mut self, n: i32) -> IoResult<()> { fn write_be_i32(&mut self, n: i32) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, 4u, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, 4u, |v| self.write_all(v))
} }
/// Write a big-endian i16 (2 bytes). /// Write a big-endian i16 (2 bytes).
#[inline] #[inline]
fn write_be_i16(&mut self, n: i16) -> IoResult<()> { fn write_be_i16(&mut self, n: i16) -> IoResult<()> {
extensions::u64_to_be_bytes(n as u64, 2u, |v| self.write(v)) extensions::u64_to_be_bytes(n as u64, 2u, |v| self.write_all(v))
} }
/// Write a big-endian IEEE754 double-precision floating-point (8 bytes). /// Write a big-endian IEEE754 double-precision floating-point (8 bytes).
@ -1166,37 +1170,37 @@ pub trait Writer {
/// Write a little-endian u64 (8 bytes). /// Write a little-endian u64 (8 bytes).
#[inline] #[inline]
fn write_le_u64(&mut self, n: u64) -> IoResult<()> { fn write_le_u64(&mut self, n: u64) -> IoResult<()> {
extensions::u64_to_le_bytes(n, 8u, |v| self.write(v)) extensions::u64_to_le_bytes(n, 8u, |v| self.write_all(v))
} }
/// Write a little-endian u32 (4 bytes). /// Write a little-endian u32 (4 bytes).
#[inline] #[inline]
fn write_le_u32(&mut self, n: u32) -> IoResult<()> { fn write_le_u32(&mut self, n: u32) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, 4u, |v| self.write_all(v))
} }
/// Write a little-endian u16 (2 bytes). /// Write a little-endian u16 (2 bytes).
#[inline] #[inline]
fn write_le_u16(&mut self, n: u16) -> IoResult<()> { fn write_le_u16(&mut self, n: u16) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, 2u, |v| self.write_all(v))
} }
/// Write a little-endian i64 (8 bytes). /// Write a little-endian i64 (8 bytes).
#[inline] #[inline]
fn write_le_i64(&mut self, n: i64) -> IoResult<()> { fn write_le_i64(&mut self, n: i64) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, 8u, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, 8u, |v| self.write_all(v))
} }
/// Write a little-endian i32 (4 bytes). /// Write a little-endian i32 (4 bytes).
#[inline] #[inline]
fn write_le_i32(&mut self, n: i32) -> IoResult<()> { fn write_le_i32(&mut self, n: i32) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, 4u, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, 4u, |v| self.write_all(v))
} }
/// Write a little-endian i16 (2 bytes). /// Write a little-endian i16 (2 bytes).
#[inline] #[inline]
fn write_le_i16(&mut self, n: i16) -> IoResult<()> { fn write_le_i16(&mut self, n: i16) -> IoResult<()> {
extensions::u64_to_le_bytes(n as u64, 2u, |v| self.write(v)) extensions::u64_to_le_bytes(n as u64, 2u, |v| self.write_all(v))
} }
/// Write a little-endian IEEE754 double-precision floating-point /// Write a little-endian IEEE754 double-precision floating-point
@ -1220,13 +1224,13 @@ pub trait Writer {
/// Write a u8 (1 byte). /// Write a u8 (1 byte).
#[inline] #[inline]
fn write_u8(&mut self, n: u8) -> IoResult<()> { fn write_u8(&mut self, n: u8) -> IoResult<()> {
self.write(&[n]) self.write_all(&[n])
} }
/// Write an i8 (1 byte). /// Write an i8 (1 byte).
#[inline] #[inline]
fn write_i8(&mut self, n: i8) -> IoResult<()> { fn write_i8(&mut self, n: i8) -> IoResult<()> {
self.write(&[n as u8]) self.write_all(&[n as u8])
} }
} }
@ -1248,8 +1252,8 @@ impl<T: Writer> ByRefWriter for T {
impl<'a> Writer for Box<Writer+'a> { impl<'a> Writer for Box<Writer+'a> {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
(&mut **self).write(buf) (&mut **self).write_all(buf)
} }
#[inline] #[inline]
@ -1260,7 +1264,7 @@ impl<'a> Writer for Box<Writer+'a> {
impl<'a> Writer for &'a mut (Writer+'a) { impl<'a> Writer for &'a mut (Writer+'a) {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { (**self).write(buf) } fn write_all(&mut self, buf: &[u8]) -> IoResult<()> { (**self).write_all(buf) }
#[inline] #[inline]
fn flush(&mut self) -> IoResult<()> { (**self).flush() } fn flush(&mut self) -> IoResult<()> { (**self).flush() }
@ -1295,7 +1299,7 @@ pub struct RefWriter<'a, W:'a> {
impl<'a, W: Writer> Writer for RefWriter<'a, W> { impl<'a, W: Writer> Writer for RefWriter<'a, W> {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { self.inner.write(buf) } fn write_all(&mut self, buf: &[u8]) -> IoResult<()> { self.inner.write_all(buf) }
#[inline] #[inline]
fn flush(&mut self) -> IoResult<()> { self.inner.flush() } fn flush(&mut self) -> IoResult<()> { self.inner.flush() }

View File

@ -142,7 +142,7 @@ impl Reader for UnixStream {
} }
impl Writer for UnixStream { impl Writer for UnixStream {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.inner.write(buf) self.inner.write(buf)
} }
} }

View File

@ -258,7 +258,7 @@ impl Reader for TcpStream {
} }
impl Writer for TcpStream { impl Writer for TcpStream {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.inner.write(buf) self.inner.write(buf)
} }
} }

View File

@ -105,7 +105,7 @@ impl Reader for PipeStream {
} }
impl Writer for PipeStream { impl Writer for PipeStream {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.inner.write(buf) self.inner.write(buf)
} }
} }

View File

@ -19,9 +19,9 @@ use result::Result::{Ok, Err};
use super::{Reader, Writer, Listener, Acceptor, Seek, SeekStyle, IoResult}; use super::{Reader, Writer, Listener, Acceptor, Seek, SeekStyle, IoResult};
impl<W: Writer> Writer for IoResult<W> { impl<W: Writer> Writer for IoResult<W> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
match *self { match *self {
Ok(ref mut writer) => writer.write(buf), Ok(ref mut writer) => writer.write_all(buf),
Err(ref e) => Err((*e).clone()) Err(ref e) => Err((*e).clone())
} }
} }
@ -85,7 +85,7 @@ mod test {
#[test] #[test]
fn test_option_writer() { fn test_option_writer() {
let mut writer: old_io::IoResult<Vec<u8>> = Ok(Vec::new()); let mut writer: old_io::IoResult<Vec<u8>> = Ok(Vec::new());
writer.write(&[0, 1, 2]).unwrap(); writer.write_all(&[0, 1, 2]).unwrap();
writer.flush().unwrap(); writer.flush().unwrap();
assert_eq!(writer.unwrap(), vec!(0, 1, 2)); assert_eq!(writer.unwrap(), vec!(0, 1, 2));
} }
@ -95,7 +95,7 @@ mod test {
let mut writer: old_io::IoResult<Vec<u8>> = let mut writer: old_io::IoResult<Vec<u8>> =
Err(old_io::standard_error(old_io::EndOfFile)); Err(old_io::standard_error(old_io::EndOfFile));
match writer.write(&[0, 0, 0]) { match writer.write_all(&[0, 0, 0]) {
Ok(..) => panic!(), Ok(..) => panic!(),
Err(e) => assert_eq!(e.kind, old_io::EndOfFile), Err(e) => assert_eq!(e.kind, old_io::EndOfFile),
} }

View File

@ -22,7 +22,7 @@
//! use std::old_io; //! use std::old_io;
//! //!
//! let mut out = old_io::stdout(); //! let mut out = old_io::stdout();
//! out.write(b"Hello, world!"); //! out.write_all(b"Hello, world!");
//! ``` //! ```
use self::StdSource::*; use self::StdSource::*;
@ -370,14 +370,14 @@ pub fn flush() {
/// Prints a string to the stdout of the current process. No newline is emitted /// Prints a string to the stdout of the current process. No newline is emitted
/// after the string is printed. /// after the string is printed.
pub fn print(s: &str) { pub fn print(s: &str) {
with_task_stdout(|io| io.write(s.as_bytes())) with_task_stdout(|io| io.write_all(s.as_bytes()))
} }
/// Prints a string to the stdout of the current process. A literal /// Prints a string to the stdout of the current process. A literal
/// `\n` character is printed to the console after the string. /// `\n` character is printed to the console after the string.
pub fn println(s: &str) { pub fn println(s: &str) {
with_task_stdout(|io| { with_task_stdout(|io| {
io.write(s.as_bytes()).and_then(|()| io.write(&[b'\n'])) io.write_all(s.as_bytes()).and_then(|()| io.write_all(&[b'\n']))
}) })
} }
@ -498,7 +498,7 @@ impl StdWriter {
} }
impl Writer for StdWriter { impl Writer for StdWriter {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
// As with stdin on windows, stdout often can't handle writes of large // As with stdin on windows, stdout often can't handle writes of large
// sizes. For an example, see #14940. For this reason, chunk the output // sizes. For an example, see #14940. For this reason, chunk the output
// buffer on windows, but on unix we can just write the whole buffer all // buffer on windows, but on unix we can just write the whole buffer all

View File

@ -83,7 +83,7 @@ pub struct NullWriter;
impl Writer for NullWriter { impl Writer for NullWriter {
#[inline] #[inline]
fn write(&mut self, _buf: &[u8]) -> old_io::IoResult<()> { Ok(()) } fn write_all(&mut self, _buf: &[u8]) -> old_io::IoResult<()> { Ok(()) }
} }
/// A `Reader` which returns an infinite stream of 0 bytes, like /dev/zero. /// A `Reader` which returns an infinite stream of 0 bytes, like /dev/zero.
@ -143,9 +143,9 @@ impl<W> MultiWriter<W> where W: Writer {
impl<W> Writer for MultiWriter<W> where W: Writer { impl<W> Writer for MultiWriter<W> where W: Writer {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> old_io::IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> old_io::IoResult<()> {
for writer in self.writers.iter_mut() { for writer in self.writers.iter_mut() {
try!(writer.write(buf)); try!(writer.write_all(buf));
} }
Ok(()) Ok(())
} }
@ -223,7 +223,7 @@ impl<R: Reader, W: Writer> TeeReader<R, W> {
impl<R: Reader, W: Writer> Reader for TeeReader<R, W> { impl<R: Reader, W: Writer> Reader for TeeReader<R, W> {
fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult<uint> { fn read(&mut self, buf: &mut [u8]) -> old_io::IoResult<uint> {
self.reader.read(buf).and_then(|len| { self.reader.read(buf).and_then(|len| {
self.writer.write(&mut buf[..len]).map(|()| len) self.writer.write_all(&mut buf[..len]).map(|()| len)
}) })
} }
} }
@ -237,7 +237,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> old_io::IoResult<()>
Err(ref e) if e.kind == old_io::EndOfFile => return Ok(()), Err(ref e) if e.kind == old_io::EndOfFile => return Ok(()),
Err(e) => return Err(e), Err(e) => return Err(e),
}; };
try!(w.write(&buf[..len])); try!(w.write_all(&buf[..len]));
} }
} }
@ -321,7 +321,7 @@ mod test {
fn test_null_writer() { fn test_null_writer() {
let mut s = NullWriter; let mut s = NullWriter;
let buf = vec![0, 0, 0]; let buf = vec![0, 0, 0];
s.write(buf.as_slice()).unwrap(); s.write_all(buf.as_slice()).unwrap();
s.flush().unwrap(); s.flush().unwrap();
} }
@ -347,7 +347,7 @@ mod test {
struct TestWriter; struct TestWriter;
impl Writer for TestWriter { impl Writer for TestWriter {
fn write(&mut self, _buf: &[u8]) -> old_io::IoResult<()> { fn write_all(&mut self, _buf: &[u8]) -> old_io::IoResult<()> {
unsafe { writes += 1 } unsafe { writes += 1 }
Ok(()) Ok(())
} }
@ -360,7 +360,7 @@ mod test {
let mut multi = MultiWriter::new(vec!(box TestWriter as Box<Writer>, let mut multi = MultiWriter::new(vec!(box TestWriter as Box<Writer>,
box TestWriter as Box<Writer>)); box TestWriter as Box<Writer>));
multi.write(&[1, 2, 3]).unwrap(); multi.write_all(&[1, 2, 3]).unwrap();
assert_eq!(2, unsafe { writes }); assert_eq!(2, unsafe { writes });
assert_eq!(0, unsafe { flushes }); assert_eq!(0, unsafe { flushes });
multi.flush().unwrap(); multi.flush().unwrap();

View File

@ -375,7 +375,7 @@ fn output(w: &mut Writer, idx: int, addr: *mut libc::c_void,
Some(string) => try!(demangle(w, string)), Some(string) => try!(demangle(w, string)),
None => try!(write!(w, "<unknown>")), None => try!(write!(w, "<unknown>")),
} }
w.write(&['\n' as u8]) w.write_all(&['\n' as u8])
} }
/// Unwind library interface used for backtraces /// Unwind library interface used for backtraces

View File

@ -67,7 +67,7 @@ impl TTY {
let mut size = winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0 }; let mut size = winsize { ws_row: 0, ws_col: 0, ws_xpixel: 0, ws_ypixel: 0 };
if c::ioctl(self.fd.fd(), TIOCGWINSZ, &mut size) == -1 { if c::ioctl(self.fd.fd(), TIOCGWINSZ, &mut size) == -1 {
Err(IoError { Err(IoError {
kind: io::OtherIoError, kind: old_io::OtherIoError,
desc: "Size of terminal could not be determined", desc: "Size of terminal could not be determined",
detail: None, detail: None,
}) })

View File

@ -25,7 +25,7 @@ use dynamic_lib::DynamicLibrary;
use ffi; use ffi;
use core::ops::Index; use core::ops::Index;
use intrinsics; use intrinsics;
use io::{IoResult, Writer}; use old_io::{IoResult, Writer};
use libc; use libc;
use mem; use mem;
use ops::Drop; use ops::Drop;
@ -363,10 +363,10 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
let bytes = unsafe { ffi::c_str_to_bytes(&ptr) }; let bytes = unsafe { ffi::c_str_to_bytes(&ptr) };
match str::from_utf8(bytes) { match str::from_utf8(bytes) {
Ok(s) => try!(demangle(w, s)), Ok(s) => try!(demangle(w, s)),
Err(..) => try!(w.write(&bytes[..bytes.len()-1])), Err(..) => try!(w.write_all(&bytes[..bytes.len()-1])),
} }
} }
try!(w.write(&['\n' as u8])); try!(w.write_all(&['\n' as u8]));
} }
Ok(()) Ok(())

View File

@ -23,7 +23,7 @@ use sys_common::{AsInner, FromInner};
use ffi::{OsStr, OsString}; use ffi::{OsStr, OsString};
use libc; use libc;
use io; use old_io;
/// Raw HANDLEs. /// Raw HANDLEs.
pub type Handle = libc::HANDLE; pub type Handle = libc::HANDLE;
@ -37,31 +37,31 @@ pub trait AsRawHandle {
fn as_raw_handle(&self) -> Handle; fn as_raw_handle(&self) -> Handle;
} }
impl AsRawHandle for io::fs::File { impl AsRawHandle for old_io::fs::File {
fn as_raw_handle(&self) -> Handle { fn as_raw_handle(&self) -> Handle {
self.as_inner().handle() self.as_inner().handle()
} }
} }
impl AsRawHandle for io::pipe::PipeStream { impl AsRawHandle for old_io::pipe::PipeStream {
fn as_raw_handle(&self) -> Handle { fn as_raw_handle(&self) -> Handle {
self.as_inner().handle() self.as_inner().handle()
} }
} }
impl AsRawHandle for io::net::pipe::UnixStream { impl AsRawHandle for old_io::net::pipe::UnixStream {
fn as_raw_handle(&self) -> Handle { fn as_raw_handle(&self) -> Handle {
self.as_inner().handle() self.as_inner().handle()
} }
} }
impl AsRawHandle for io::net::pipe::UnixListener { impl AsRawHandle for old_io::net::pipe::UnixListener {
fn as_raw_handle(&self) -> Handle { fn as_raw_handle(&self) -> Handle {
self.as_inner().handle() self.as_inner().handle()
} }
} }
impl AsRawHandle for io::net::pipe::UnixAcceptor { impl AsRawHandle for old_io::net::pipe::UnixAcceptor {
fn as_raw_handle(&self) -> Handle { fn as_raw_handle(&self) -> Handle {
self.as_inner().handle() self.as_inner().handle()
} }
@ -72,25 +72,25 @@ pub trait AsRawSocket {
fn as_raw_socket(&self) -> Socket; fn as_raw_socket(&self) -> Socket;
} }
impl AsRawSocket for io::net::tcp::TcpStream { impl AsRawSocket for old_io::net::tcp::TcpStream {
fn as_raw_socket(&self) -> Socket { fn as_raw_socket(&self) -> Socket {
self.as_inner().fd() self.as_inner().fd()
} }
} }
impl AsRawSocket for io::net::tcp::TcpListener { impl AsRawSocket for old_io::net::tcp::TcpListener {
fn as_raw_socket(&self) -> Socket { fn as_raw_socket(&self) -> Socket {
self.as_inner().socket() self.as_inner().socket()
} }
} }
impl AsRawSocket for io::net::tcp::TcpAcceptor { impl AsRawSocket for old_io::net::tcp::TcpAcceptor {
fn as_raw_socket(&self) -> Socket { fn as_raw_socket(&self) -> Socket {
self.as_inner().socket() self.as_inner().socket()
} }
} }
impl AsRawSocket for io::net::udp::UdpSocket { impl AsRawSocket for old_io::net::udp::UdpSocket {
fn as_raw_socket(&self) -> Socket { fn as_raw_socket(&self) -> Socket {
self.as_inner().fd() self.as_inner().fd()
} }

View File

@ -18,16 +18,16 @@ use sys::os::fill_utf16_buf_and_decode;
use path; use path;
use ptr; use ptr;
use str; use str;
use io; use old_io;
use prelude::v1::*; use prelude::v1::*;
use sys; use sys;
use sys::os; use sys::os;
use sys_common::{keep_going, eof, mkerr_libc}; use sys_common::{keep_going, eof, mkerr_libc};
use io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode}; use old_io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode};
use io::{IoResult, IoError, FileStat, SeekStyle}; use old_io::{IoResult, IoError, FileStat, SeekStyle};
use io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append}; use old_io::{Read, Truncate, SeekCur, SeekSet, ReadWrite, SeekEnd, Append};
pub type fd_t = libc::c_int; pub type fd_t = libc::c_int;
@ -130,7 +130,7 @@ impl FileDesc {
return ret; return ret;
} }
pub fn fstat(&self) -> IoResult<io::FileStat> { pub fn fstat(&self) -> IoResult<old_io::FileStat> {
let mut stat: libc::stat = unsafe { mem::zeroed() }; let mut stat: libc::stat = unsafe { mem::zeroed() };
match unsafe { libc::fstat(self.fd(), &mut stat) } { match unsafe { libc::fstat(self.fd(), &mut stat) } {
0 => Ok(mkstat(&stat)), 0 => Ok(mkstat(&stat)),
@ -268,7 +268,7 @@ pub fn readdir(p: &Path) -> IoResult<Vec<Path>> {
Err(..) => { Err(..) => {
assert!(libc::FindClose(find_handle) != 0); assert!(libc::FindClose(find_handle) != 0);
return Err(IoError { return Err(IoError {
kind: io::InvalidInput, kind: old_io::InvalidInput,
desc: "path was not valid UTF-16", desc: "path was not valid UTF-16",
detail: Some(format!("path was not valid UTF-16: {:?}", filename)), detail: Some(format!("path was not valid UTF-16: {:?}", filename)),
}) })
@ -303,14 +303,14 @@ pub fn unlink(p: &Path) -> IoResult<()> {
// however, it cannot. To keep the two platforms in line with // however, it cannot. To keep the two platforms in line with
// respect to their behavior, catch this case on windows, attempt to // respect to their behavior, catch this case on windows, attempt to
// change it to read-write, and then remove the file. // change it to read-write, and then remove the file.
if e.kind == io::PermissionDenied { if e.kind == old_io::PermissionDenied {
let stat = match stat(p) { let stat = match stat(p) {
Ok(stat) => stat, Ok(stat) => stat,
Err(..) => return Err(e), Err(..) => return Err(e),
}; };
if stat.perm.intersects(io::USER_WRITE) { return Err(e) } if stat.perm.intersects(old_io::USER_WRITE) { return Err(e) }
match chmod(p, (stat.perm | io::USER_WRITE).bits() as uint) { match chmod(p, (stat.perm | old_io::USER_WRITE).bits() as uint) {
Ok(()) => do_unlink(&p_utf16), Ok(()) => do_unlink(&p_utf16),
Err(..) => { Err(..) => {
// Try to put it back as we found it // Try to put it back as we found it
@ -406,12 +406,12 @@ fn mkstat(stat: &libc::stat) -> FileStat {
FileStat { FileStat {
size: stat.st_size as u64, size: stat.st_size as u64,
kind: match (stat.st_mode as libc::c_int) & libc::S_IFMT { kind: match (stat.st_mode as libc::c_int) & libc::S_IFMT {
libc::S_IFREG => io::FileType::RegularFile, libc::S_IFREG => old_io::FileType::RegularFile,
libc::S_IFDIR => io::FileType::Directory, libc::S_IFDIR => old_io::FileType::Directory,
libc::S_IFIFO => io::FileType::NamedPipe, libc::S_IFIFO => old_io::FileType::NamedPipe,
libc::S_IFBLK => io::FileType::BlockSpecial, libc::S_IFBLK => old_io::FileType::BlockSpecial,
libc::S_IFLNK => io::FileType::Symlink, libc::S_IFLNK => old_io::FileType::Symlink,
_ => io::FileType::Unknown, _ => old_io::FileType::Unknown,
}, },
perm: FilePermission::from_bits_truncate(stat.st_mode as u32), perm: FilePermission::from_bits_truncate(stat.st_mode as u32),
created: stat.st_ctime as u64, created: stat.st_ctime as u64,

View File

@ -22,7 +22,7 @@ use prelude::v1::*;
use num; use num;
use mem; use mem;
use io::{self, IoResult, IoError}; use old_io::{self, IoResult, IoError};
use sync::{Once, ONCE_INIT}; use sync::{Once, ONCE_INIT};
macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => ( macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
@ -99,43 +99,43 @@ pub fn last_gai_error(_errno: i32) -> IoError {
/// Convert an `errno` value into a high-level error variant and description. /// Convert an `errno` value into a high-level error variant and description.
pub fn decode_error(errno: i32) -> IoError { pub fn decode_error(errno: i32) -> IoError {
let (kind, desc) = match errno { let (kind, desc) = match errno {
libc::EOF => (io::EndOfFile, "end of file"), libc::EOF => (old_io::EndOfFile, "end of file"),
libc::ERROR_NO_DATA => (io::BrokenPipe, "the pipe is being closed"), libc::ERROR_NO_DATA => (old_io::BrokenPipe, "the pipe is being closed"),
libc::ERROR_FILE_NOT_FOUND => (io::FileNotFound, "file not found"), libc::ERROR_FILE_NOT_FOUND => (old_io::FileNotFound, "file not found"),
libc::ERROR_INVALID_NAME => (io::InvalidInput, "invalid file name"), libc::ERROR_INVALID_NAME => (old_io::InvalidInput, "invalid file name"),
libc::WSAECONNREFUSED => (io::ConnectionRefused, "connection refused"), libc::WSAECONNREFUSED => (old_io::ConnectionRefused, "connection refused"),
libc::WSAECONNRESET => (io::ConnectionReset, "connection reset"), libc::WSAECONNRESET => (old_io::ConnectionReset, "connection reset"),
libc::ERROR_ACCESS_DENIED | libc::WSAEACCES => libc::ERROR_ACCESS_DENIED | libc::WSAEACCES =>
(io::PermissionDenied, "permission denied"), (old_io::PermissionDenied, "permission denied"),
libc::WSAEWOULDBLOCK => { libc::WSAEWOULDBLOCK => {
(io::ResourceUnavailable, "resource temporarily unavailable") (old_io::ResourceUnavailable, "resource temporarily unavailable")
} }
libc::WSAENOTCONN => (io::NotConnected, "not connected"), libc::WSAENOTCONN => (old_io::NotConnected, "not connected"),
libc::WSAECONNABORTED => (io::ConnectionAborted, "connection aborted"), libc::WSAECONNABORTED => (old_io::ConnectionAborted, "connection aborted"),
libc::WSAEADDRNOTAVAIL => (io::ConnectionRefused, "address not available"), libc::WSAEADDRNOTAVAIL => (old_io::ConnectionRefused, "address not available"),
libc::WSAEADDRINUSE => (io::ConnectionRefused, "address in use"), libc::WSAEADDRINUSE => (old_io::ConnectionRefused, "address in use"),
libc::ERROR_BROKEN_PIPE => (io::EndOfFile, "the pipe has ended"), libc::ERROR_BROKEN_PIPE => (old_io::EndOfFile, "the pipe has ended"),
libc::ERROR_OPERATION_ABORTED => libc::ERROR_OPERATION_ABORTED =>
(io::TimedOut, "operation timed out"), (old_io::TimedOut, "operation timed out"),
libc::WSAEINVAL => (io::InvalidInput, "invalid argument"), libc::WSAEINVAL => (old_io::InvalidInput, "invalid argument"),
libc::ERROR_CALL_NOT_IMPLEMENTED => libc::ERROR_CALL_NOT_IMPLEMENTED =>
(io::IoUnavailable, "function not implemented"), (old_io::IoUnavailable, "function not implemented"),
libc::ERROR_INVALID_HANDLE => libc::ERROR_INVALID_HANDLE =>
(io::MismatchedFileTypeForOperation, (old_io::MismatchedFileTypeForOperation,
"invalid handle provided to function"), "invalid handle provided to function"),
libc::ERROR_NOTHING_TO_TERMINATE => libc::ERROR_NOTHING_TO_TERMINATE =>
(io::InvalidInput, "no process to kill"), (old_io::InvalidInput, "no process to kill"),
libc::ERROR_ALREADY_EXISTS => libc::ERROR_ALREADY_EXISTS =>
(io::PathAlreadyExists, "path already exists"), (old_io::PathAlreadyExists, "path already exists"),
// libuv maps this error code to EISDIR. we do too. if it is found // libuv maps this error code to EISDIR. we do too. if it is found
// to be incorrect, we can add in some more machinery to only // to be incorrect, we can add in some more machinery to only
// return this message when ERROR_INVALID_FUNCTION after certain // return this message when ERROR_INVALID_FUNCTION after certain
// Windows calls. // Windows calls.
libc::ERROR_INVALID_FUNCTION => (io::InvalidInput, libc::ERROR_INVALID_FUNCTION => (old_io::InvalidInput,
"illegal operation on a directory"), "illegal operation on a directory"),
_ => (io::OtherIoError, "unknown error") _ => (old_io::OtherIoError, "unknown error")
}; };
IoError { kind: kind, desc: desc, detail: None } IoError { kind: kind, desc: desc, detail: None }
} }
@ -185,7 +185,7 @@ pub fn init_net() {
pub fn unimpl() -> IoError { pub fn unimpl() -> IoError {
IoError { IoError {
kind: io::IoUnavailable, kind: old_io::IoUnavailable,
desc: "operation is not implemented", desc: "operation is not implemented",
detail: None, detail: None,
} }
@ -199,7 +199,7 @@ pub fn to_utf16(s: Option<&str>) -> IoResult<Vec<u16>> {
s s
}), }),
None => Err(IoError { None => Err(IoError {
kind: io::InvalidInput, kind: old_io::InvalidInput,
desc: "valid unicode input required", desc: "valid unicode input required",
detail: None detail: None
}) })

View File

@ -16,7 +16,7 @@
use prelude::v1::*; use prelude::v1::*;
use fmt; use fmt;
use io::{IoResult, IoError}; use old_io::{IoResult, IoError};
use iter::repeat; use iter::repeat;
use libc::{c_int, c_void}; use libc::{c_int, c_void};
use libc; use libc;
@ -162,7 +162,7 @@ pub fn fill_utf16_buf_and_decode<F>(mut f: F) -> Option<String> where
pub fn getcwd() -> IoResult<Path> { pub fn getcwd() -> IoResult<Path> {
use libc::DWORD; use libc::DWORD;
use libc::GetCurrentDirectoryW; use libc::GetCurrentDirectoryW;
use io::OtherIoError; use old_io::OtherIoError;
let mut buf = [0 as u16; BUF_BYTES]; let mut buf = [0 as u16; BUF_BYTES];
unsafe { unsafe {

View File

@ -88,7 +88,7 @@ use prelude::v1::*;
use libc; use libc;
use ffi::CString; use ffi::CString;
use io::{self, IoError, IoResult}; use old_io::{self, IoError, IoResult};
use mem; use mem;
use ptr; use ptr;
use str; use str;
@ -202,7 +202,7 @@ pub fn await(handle: libc::HANDLE, deadline: u64,
fn epipe() -> IoError { fn epipe() -> IoError {
IoError { IoError {
kind: io::EndOfFile, kind: old_io::EndOfFile,
desc: "the pipe has ended", desc: "the pipe has ended",
detail: None, detail: None,
} }
@ -485,7 +485,7 @@ impl UnixStream {
let amt = offset + bytes_written as uint; let amt = offset + bytes_written as uint;
return if amt > 0 { return if amt > 0 {
Err(IoError { Err(IoError {
kind: io::ShortWrite(amt), kind: old_io::ShortWrite(amt),
desc: "short write during write", desc: "short write during write",
detail: None, detail: None,
}) })

View File

@ -14,10 +14,10 @@ use collections;
use ffi::CString; use ffi::CString;
use hash::Hash; use hash::Hash;
use collections::hash_map::Hasher; use collections::hash_map::Hasher;
use io::fs::PathExtensions; use old_io::fs::PathExtensions;
use io::process::{ProcessExit, ExitStatus, ExitSignal}; use old_io::process::{ProcessExit, ExitStatus, ExitSignal};
use io::{IoResult, IoError}; use old_io::{IoResult, IoError};
use io; use old_io;
use libc::{pid_t, c_void, c_int}; use libc::{pid_t, c_void, c_int};
use libc; use libc;
use mem; use mem;
@ -84,7 +84,7 @@ impl Process {
Err(super::last_error()) Err(super::last_error())
} else if status != libc::STILL_ACTIVE { } else if status != libc::STILL_ACTIVE {
Err(IoError { Err(IoError {
kind: io::InvalidInput, kind: old_io::InvalidInput,
desc: "no process to kill", desc: "no process to kill",
detail: None, detail: None,
}) })
@ -97,7 +97,7 @@ impl Process {
super::mkerr_winbool(ret) super::mkerr_winbool(ret)
} }
_ => Err(IoError { _ => Err(IoError {
kind: io::IoUnavailable, kind: old_io::IoUnavailable,
desc: "unsupported signal on windows", desc: "unsupported signal on windows",
detail: None, detail: None,
}) })
@ -133,7 +133,7 @@ impl Process {
if cfg.gid().is_some() || cfg.uid().is_some() { if cfg.gid().is_some() || cfg.uid().is_some() {
return Err(IoError { return Err(IoError {
kind: io::IoUnavailable, kind: old_io::IoUnavailable,
desc: "unsupported gid/uid requested on windows", desc: "unsupported gid/uid requested on windows",
detail: None, detail: None,
}) })

View File

@ -8,8 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use io::net::ip; use old_io::net::ip;
use io::IoResult; use old_io::IoResult;
use libc; use libc;
use mem; use mem;
use ptr; use ptr;

View File

@ -26,7 +26,7 @@ use prelude::v1::*;
use libc; use libc;
use ptr; use ptr;
use io::IoResult; use old_io::IoResult;
use sync::mpsc::{channel, Sender, Receiver, TryRecvError}; use sync::mpsc::{channel, Sender, Receiver, TryRecvError};
use sys::c; use sys::c;
use sys::fs::FileDesc; use sys::fs::FileDesc;

View File

@ -27,7 +27,7 @@
use prelude::v1::*; use prelude::v1::*;
use io::{self, IoError, IoResult, MemReader}; use old_io::{self, IoError, IoResult, MemReader};
use iter::repeat; use iter::repeat;
use libc::types::os::arch::extra::LPCVOID; use libc::types::os::arch::extra::LPCVOID;
use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID}; use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID};
@ -44,7 +44,7 @@ use super::c::{GetConsoleScreenBufferInfo};
fn invalid_encoding() -> IoError { fn invalid_encoding() -> IoError {
IoError { IoError {
kind: io::InvalidInput, kind: old_io::InvalidInput,
desc: "text was not valid unicode", desc: "text was not valid unicode",
detail: None, detail: None,
} }
@ -83,7 +83,7 @@ impl TTY {
}) })
} else { } else {
Err(IoError { Err(IoError {
kind: io::MismatchedFileTypeForOperation, kind: old_io::MismatchedFileTypeForOperation,
desc: "invalid handle provided to function", desc: "invalid handle provided to function",
detail: None, detail: None,
}) })

View File

@ -362,10 +362,10 @@ impl EmitterWriter {
} }
impl Writer for Destination { impl Writer for Destination {
fn write(&mut self, bytes: &[u8]) -> old_io::IoResult<()> { fn write_all(&mut self, bytes: &[u8]) -> old_io::IoResult<()> {
match *self { match *self {
Terminal(ref mut t) => t.write(bytes), Terminal(ref mut t) => t.write_all(bytes),
Raw(ref mut w) => w.write(bytes), Raw(ref mut w) => w.write_all(bytes),
} }
} }
} }

View File

@ -76,8 +76,8 @@ pub struct WriterWrapper {
impl Writer for WriterWrapper { impl Writer for WriterWrapper {
#[inline] #[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.wrapped.write(buf) self.wrapped.write_all(buf)
} }
#[inline] #[inline]

View File

@ -83,7 +83,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
.as_slice(), .as_slice(),
&[Number(color as int)], &mut Variables::new()); &[Number(color as int)], &mut Variables::new());
if s.is_ok() { if s.is_ok() {
try!(self.out.write(s.unwrap().as_slice())); try!(self.out.write_all(s.unwrap().as_slice()));
return Ok(true) return Ok(true)
} }
} }
@ -100,7 +100,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
.as_slice(), .as_slice(),
&[Number(color as int)], &mut Variables::new()); &[Number(color as int)], &mut Variables::new());
if s.is_ok() { if s.is_ok() {
try!(self.out.write(s.unwrap().as_slice())); try!(self.out.write_all(s.unwrap().as_slice()));
return Ok(true) return Ok(true)
} }
} }
@ -119,7 +119,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
&[], &[],
&mut Variables::new()); &mut Variables::new());
if s.is_ok() { if s.is_ok() {
try!(self.out.write(s.unwrap().as_slice())); try!(self.out.write_all(s.unwrap().as_slice()));
return Ok(true) return Ok(true)
} }
} }
@ -154,7 +154,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
expand(op.as_slice(), &[], &mut Variables::new()) expand(op.as_slice(), &[], &mut Variables::new())
}); });
if s.is_ok() { if s.is_ok() {
return self.out.write(s.unwrap().as_slice()) return self.out.write_all(s.unwrap().as_slice())
} }
Ok(()) Ok(())
} }
@ -221,8 +221,8 @@ impl<T: Writer+Send> TerminfoTerminal<T> {
impl<T: Writer> Writer for TerminfoTerminal<T> { impl<T: Writer> Writer for TerminfoTerminal<T> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.out.write(buf) self.out.write_all(buf)
} }
fn flush(&mut self) -> IoResult<()> { fn flush(&mut self) -> IoResult<()> {

View File

@ -14,7 +14,7 @@
extern crate libc; extern crate libc;
use std::io::IoResult; use std::old_io::IoResult;
use attr; use attr;
use color; use color;
@ -130,8 +130,8 @@ impl<T: Writer+Send> WinConsole<T> {
} }
impl<T: Writer> Writer for WinConsole<T> { impl<T: Writer> Writer for WinConsole<T> {
fn write(&mut self, buf: &[u8]) -> IoResult<()> { fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
self.buf.write(buf) self.buf.write_all(buf)
} }
fn flush(&mut self) -> IoResult<()> { fn flush(&mut self) -> IoResult<()> {

View File

@ -496,20 +496,20 @@ impl<T: Writer> ConsoleTestState<T> {
if self.use_color { if self.use_color {
try!(term.fg(color)); try!(term.fg(color));
} }
try!(term.write(word.as_bytes())); try!(term.write_all(word.as_bytes()));
if self.use_color { if self.use_color {
try!(term.reset()); try!(term.reset());
} }
Ok(()) Ok(())
} }
Raw(ref mut stdout) => stdout.write(word.as_bytes()) Raw(ref mut stdout) => stdout.write_all(word.as_bytes())
} }
} }
pub fn write_plain(&mut self, s: &str) -> old_io::IoResult<()> { pub fn write_plain(&mut self, s: &str) -> old_io::IoResult<()> {
match self.out { match self.out {
Pretty(ref mut term) => term.write(s.as_bytes()), Pretty(ref mut term) => term.write_all(s.as_bytes()),
Raw(ref mut stdout) => stdout.write(s.as_bytes()) Raw(ref mut stdout) => stdout.write_all(s.as_bytes())
} }
} }
@ -558,7 +558,7 @@ impl<T: Writer> ConsoleTestState<T> {
TrMetrics(ref mm) => mm.fmt_metrics(), TrMetrics(ref mm) => mm.fmt_metrics(),
TrBench(ref bs) => fmt_bench_samples(bs) TrBench(ref bs) => fmt_bench_samples(bs)
}, test.name.as_slice()); }, test.name.as_slice());
o.write(s.as_bytes()) o.write_all(s.as_bytes())
} }
} }
} }

View File

@ -156,7 +156,7 @@ fn assignment(mut a: u64, b: u64, c: f64) {
} }
fn function_call(x: u64, y: u64, z: f64) { fn function_call(x: u64, y: u64, z: f64) {
std::io::stdio::print("Hi!") std::old_io::stdio::print("Hi!")
} }
fn identifier(x: u64, y: u64, z: f64) -> u64 { fn identifier(x: u64, y: u64, z: f64) -> u64 {

View File

@ -16,7 +16,7 @@
#![feature(asm)] #![feature(asm)]
use std::io::process::Command; use std::old_io::process::Command;
use std::os; use std::os;
// lifted from the test module // lifted from the test module

View File

@ -17,15 +17,15 @@ extern crate log;
extern crate libc; extern crate libc;
use std::sync::mpsc::channel; use std::sync::mpsc::channel;
use std::io::net::tcp::{TcpListener, TcpStream}; use std::old_io::net::tcp::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener}; use std::old_io::{Acceptor, Listener};
use std::thread::{Builder, Thread}; use std::thread::{Builder, Thread};
use std::time::Duration; use std::time::Duration;
fn main() { fn main() {
// This test has a chance to time out, try to not let it time out // This test has a chance to time out, try to not let it time out
Thread::spawn(move|| -> () { Thread::spawn(move|| -> () {
use std::io::timer; use std::old_io::timer;
timer::sleep(Duration::milliseconds(30 * 1000)); timer::sleep(Duration::milliseconds(30 * 1000));
println!("timed out!"); println!("timed out!");
unsafe { libc::exit(1) } unsafe { libc::exit(1) }