Skip to content

Commit

Permalink
std: Rename Writer::write to Writer::write_all
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
alexcrichton committed Jan 23, 2015
1 parent 1976093 commit a1bfa26
Show file tree
Hide file tree
Showing 36 changed files with 221 additions and 218 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/procsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
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 } =
process.wait_with_output().unwrap();
Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
match cmd.spawn() {
Ok(mut process) => {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,7 @@ fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) {
fn dump_output_file(config: &Config, testfile: &Path,
out: &str, extension: &str) {
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 {
Expand Down
2 changes: 1 addition & 1 deletion src/librbml/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl SeekableMemWriter {

impl Writer for SeekableMemWriter {
#[inline]
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
if self.pos == self.buf.len() {
self.buf.push_all(buf)
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,11 @@ pub mod writer {

fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
match size {
1u => w.write(&[0x80u8 | (n as u8)]),
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
1u => w.write_all(&[0x80u8 | (n as u8)]),
2u => w.write_all(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
3u => w.write_all(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) 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]),
_ => Err(old_io::IoError {
kind: old_io::OtherIoError,
Expand Down Expand Up @@ -760,7 +760,7 @@ pub mod writer {
// Write a placeholder four-byte size.
self.size_positions.push(try!(self.writer.tell()) as uint);
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
self.writer.write(zeroes)
self.writer.write_all(zeroes)
}

pub fn end_tag(&mut self) -> EncodeResult {
Expand All @@ -786,7 +786,7 @@ pub mod writer {
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, b.len()));
self.writer.write(b)
self.writer.write_all(b)
}

pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) -> EncodeResult {
Expand Down Expand Up @@ -839,12 +839,12 @@ pub mod writer {

pub fn wr_bytes(&mut self, b: &[u8]) -> EncodeResult {
debug!("Write {:?} bytes", b.len());
self.writer.write(b)
self.writer.write_all(b)
}

pub fn wr_str(&mut self, s: &str) -> EncodeResult {
debug!("Write str: {:?}", s);
self.writer.write(s.as_bytes())
self.writer.write_all(s.as_bytes())
}
}

Expand Down
54 changes: 27 additions & 27 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn encode_trait_ref<'a, 'tcx>(rbml_w: &mut Encoder,
// Item info table encoding
fn encode_family(rbml_w: &mut Encoder, c: char) {
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();
}

Expand All @@ -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) {
rbml_w.start_tag(tag_items_data_item_variant);
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.start_tag(tag_mod_child);
Expand Down Expand Up @@ -259,7 +259,7 @@ fn encode_symbol(ecx: &EncodeContext,
match ecx.item_symbols.borrow().get(&id) {
Some(x) => {
debug!("encode_symbol(id={}, str={})", id, *x);
rbml_w.writer.write(x.as_bytes());
rbml_w.writer.write_all(x.as_bytes());
}
None => {
ecx.diag.handler().bug(
Expand All @@ -274,14 +274,14 @@ fn encode_disr_val(_: &EncodeContext,
disr_val: ty::Disr) {
rbml_w.start_tag(tag_disr_val);
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();
}

fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
rbml_w.start_tag(tag_items_data_parent_item);
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();
}

Expand All @@ -299,7 +299,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
encode_def_id(rbml_w, f.id);
rbml_w.start_tag(tag_item_field_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();
}
Expand Down Expand Up @@ -637,17 +637,17 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
// Encode the base self type.
match *explicit_self {
ty::StaticExplicitSelfCategory => {
rbml_w.writer.write(&[ 's' as u8 ]);
rbml_w.writer.write_all(&[ 's' as u8 ]);
}
ty::ByValueExplicitSelfCategory => {
rbml_w.writer.write(&[ 'v' as u8 ]);
rbml_w.writer.write_all(&[ 'v' as u8 ]);
}
ty::ByBoxExplicitSelfCategory => {
rbml_w.writer.write(&[ '~' as u8 ]);
rbml_w.writer.write_all(&[ '~' as u8 ]);
}
ty::ByReferenceExplicitSelfCategory(_, m) => {
// FIXME(#4846) encode custom lifetime
rbml_w.writer.write(&['&' as u8]);
rbml_w.writer.write_all(&['&' as u8]);
encode_mutability(rbml_w, m);
}
}
Expand All @@ -657,21 +657,21 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
fn encode_mutability(rbml_w: &mut Encoder,
m: ast::Mutability) {
match m {
ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); }
ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); }
ast::MutImmutable => { rbml_w.writer.write_all(&[ 'i' as u8 ]); }
ast::MutMutable => { rbml_w.writer.write_all(&[ 'm' as u8 ]); }
}
}
}

fn encode_item_sort(rbml_w: &mut Encoder, sort: char) {
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();
}

fn encode_parent_sort(rbml_w: &mut Encoder, sort: char) {
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();
}

Expand All @@ -680,7 +680,7 @@ fn encode_provided_source(rbml_w: &mut Encoder,
for source in source_opt.iter() {
rbml_w.start_tag(tag_item_method_provided_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();
}
}
Expand Down Expand Up @@ -927,7 +927,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
rbml_w.start_tag(tag_method_argument_name);
if let ast::PatIdent(_, ref path1, _) = arg.pat.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();
}
Expand Down Expand Up @@ -1647,7 +1647,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::MetaWord(ref name) => {
rbml_w.start_tag(tag_meta_item_word);
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();
}
Expand All @@ -1656,10 +1656,10 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::LitStr(ref value, _) => {
rbml_w.start_tag(tag_meta_item_name_value);
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.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();
}
Expand All @@ -1669,7 +1669,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
ast::MetaList(ref name, ref items) => {
rbml_w.start_tag(tag_meta_item_list);
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();
for inner_item in items.iter() {
encode_meta_item(rbml_w, &**inner_item);
Expand Down Expand Up @@ -1801,7 +1801,7 @@ fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) {
rbml_w.end_tag();

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();
Expand Down Expand Up @@ -1981,29 +1981,29 @@ fn encode_crate_dep(rbml_w: &mut Encoder,
dep: decoder::CrateDep) {
rbml_w.start_tag(tag_crate_dep);
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.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();
}

fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) {
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();
}

fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) {
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();
}

fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) {
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();
}

Expand All @@ -2017,7 +2017,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
cstore::RequireStatic => "s",
})).to_string())
}).collect::<Vec<String>>();
rbml_w.writer.write(s.connect(",").as_bytes());
rbml_w.writer.write_all(s.connect(",").as_bytes());
}
None => {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
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 => {}
}
let pos = w.tell().unwrap();
Expand Down
7 changes: 3 additions & 4 deletions src/librustc_trans/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,7 @@ fn link_rlib<'a>(sess: &'a Session,
// the same filename for metadata (stomping over one another)
let tmpdir = TempDir::new("rustc").ok().expect("needs a temp dir");
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(..) => {}
Err(e) => {
sess.err(&format!("failed to write {}: {}",
Expand Down Expand Up @@ -674,10 +673,10 @@ fn write_rlib_bytecode_object_v1<T: Writer>(writer: &mut T,
-> ::std::old_io::IoResult<()> {
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_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 =
RLIB_BYTECODE_OBJECT_MAGIC.len() + // magic id
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ fn render_sources(cx: &mut Context,
/// Writes the entire contents of a string to a destination, not attempting to
/// catch any errors.
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
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/failure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ thread_local! {
}

impl Writer for Stdio {
fn write(&mut self, bytes: &[u8]) -> IoResult<()> {
fn write_all(&mut self, bytes: &[u8]) -> IoResult<()> {
let _ = self.write_bytes(bytes);
Ok(())
}
Expand Down
Loading

0 comments on commit a1bfa26

Please sign in to comment.