Skip to content

Commit c4f1d89

Browse files
committed
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]
1 parent 05a9230 commit c4f1d89

38 files changed

+225
-222
lines changed

Diff for: src/compiletest/procsrv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn run(lib_path: &str,
4747
match cmd.spawn() {
4848
Ok(mut process) => {
4949
for input in input.iter() {
50-
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
50+
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
5151
}
5252
let ProcessOutput { status, output, error } =
5353
process.wait_with_output().unwrap();
@@ -79,7 +79,7 @@ pub fn run_background(lib_path: &str,
7979
match cmd.spawn() {
8080
Ok(mut process) => {
8181
for input in input.iter() {
82-
process.stdin.as_mut().unwrap().write(input.as_bytes()).unwrap();
82+
process.stdin.as_mut().unwrap().write_all(input.as_bytes()).unwrap();
8383
}
8484

8585
Some(process)

Diff for: src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ fn dump_output(config: &Config, testfile: &Path, out: &str, err: &str) {
14011401
fn dump_output_file(config: &Config, testfile: &Path,
14021402
out: &str, extension: &str) {
14031403
let outfile = make_out_name(config, testfile, extension);
1404-
File::create(&outfile).write(out.as_bytes()).unwrap();
1404+
File::create(&outfile).write_all(out.as_bytes()).unwrap();
14051405
}
14061406

14071407
fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path {

Diff for: src/librbml/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl SeekableMemWriter {
8080

8181
impl Writer for SeekableMemWriter {
8282
#[inline]
83-
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
83+
fn write_all(&mut self, buf: &[u8]) -> IoResult<()> {
8484
if self.pos == self.buf.len() {
8585
self.buf.push_all(buf)
8686
} else {

Diff for: src/librbml/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ pub mod writer {
708708

709709
fn write_sized_vuint<W: Writer>(w: &mut W, n: uint, size: uint) -> EncodeResult {
710710
match size {
711-
1u => w.write(&[0x80u8 | (n as u8)]),
712-
2u => w.write(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
713-
3u => w.write(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
711+
1u => w.write_all(&[0x80u8 | (n as u8)]),
712+
2u => w.write_all(&[0x40u8 | ((n >> 8_u) as u8), n as u8]),
713+
3u => w.write_all(&[0x20u8 | ((n >> 16_u) as u8), (n >> 8_u) as u8,
714714
n as u8]),
715-
4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
715+
4u => w.write_all(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
716716
(n >> 8_u) as u8, n as u8]),
717717
_ => Err(old_io::IoError {
718718
kind: old_io::OtherIoError,
@@ -760,7 +760,7 @@ pub mod writer {
760760
// Write a placeholder four-byte size.
761761
self.size_positions.push(try!(self.writer.tell()) as uint);
762762
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
763-
self.writer.write(zeroes)
763+
self.writer.write_all(zeroes)
764764
}
765765

766766
pub fn end_tag(&mut self) -> EncodeResult {
@@ -786,7 +786,7 @@ pub mod writer {
786786
pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) -> EncodeResult {
787787
try!(write_vuint(self.writer, tag_id));
788788
try!(write_vuint(self.writer, b.len()));
789-
self.writer.write(b)
789+
self.writer.write_all(b)
790790
}
791791

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

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

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

Diff for: src/librustc/metadata/encoder.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn encode_trait_ref<'a, 'tcx>(rbml_w: &mut Encoder,
122122
// Item info table encoding
123123
fn encode_family(rbml_w: &mut Encoder, c: char) {
124124
rbml_w.start_tag(tag_items_data_item_family);
125-
rbml_w.writer.write(&[c as u8]);
125+
rbml_w.writer.write_all(&[c as u8]);
126126
rbml_w.end_tag();
127127
}
128128

@@ -149,7 +149,7 @@ fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
149149
fn encode_variant_id(rbml_w: &mut Encoder, vid: DefId) {
150150
rbml_w.start_tag(tag_items_data_item_variant);
151151
let s = def_to_string(vid);
152-
rbml_w.writer.write(s.as_bytes());
152+
rbml_w.writer.write_all(s.as_bytes());
153153
rbml_w.end_tag();
154154

155155
rbml_w.start_tag(tag_mod_child);
@@ -259,7 +259,7 @@ fn encode_symbol(ecx: &EncodeContext,
259259
match ecx.item_symbols.borrow().get(&id) {
260260
Some(x) => {
261261
debug!("encode_symbol(id={}, str={})", id, *x);
262-
rbml_w.writer.write(x.as_bytes());
262+
rbml_w.writer.write_all(x.as_bytes());
263263
}
264264
None => {
265265
ecx.diag.handler().bug(
@@ -274,14 +274,14 @@ fn encode_disr_val(_: &EncodeContext,
274274
disr_val: ty::Disr) {
275275
rbml_w.start_tag(tag_disr_val);
276276
let s = disr_val.to_string();
277-
rbml_w.writer.write(s.as_bytes());
277+
rbml_w.writer.write_all(s.as_bytes());
278278
rbml_w.end_tag();
279279
}
280280

281281
fn encode_parent_item(rbml_w: &mut Encoder, id: DefId) {
282282
rbml_w.start_tag(tag_items_data_parent_item);
283283
let s = def_to_string(id);
284-
rbml_w.writer.write(s.as_bytes());
284+
rbml_w.writer.write_all(s.as_bytes());
285285
rbml_w.end_tag();
286286
}
287287

@@ -299,7 +299,7 @@ fn encode_struct_fields(rbml_w: &mut Encoder,
299299
encode_def_id(rbml_w, f.id);
300300
rbml_w.start_tag(tag_item_field_origin);
301301
let s = def_to_string(origin);
302-
rbml_w.writer.write(s.as_bytes());
302+
rbml_w.writer.write_all(s.as_bytes());
303303
rbml_w.end_tag();
304304
rbml_w.end_tag();
305305
}
@@ -637,17 +637,17 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
637637
// Encode the base self type.
638638
match *explicit_self {
639639
ty::StaticExplicitSelfCategory => {
640-
rbml_w.writer.write(&[ 's' as u8 ]);
640+
rbml_w.writer.write_all(&[ 's' as u8 ]);
641641
}
642642
ty::ByValueExplicitSelfCategory => {
643-
rbml_w.writer.write(&[ 'v' as u8 ]);
643+
rbml_w.writer.write_all(&[ 'v' as u8 ]);
644644
}
645645
ty::ByBoxExplicitSelfCategory => {
646-
rbml_w.writer.write(&[ '~' as u8 ]);
646+
rbml_w.writer.write_all(&[ '~' as u8 ]);
647647
}
648648
ty::ByReferenceExplicitSelfCategory(_, m) => {
649649
// FIXME(#4846) encode custom lifetime
650-
rbml_w.writer.write(&['&' as u8]);
650+
rbml_w.writer.write_all(&['&' as u8]);
651651
encode_mutability(rbml_w, m);
652652
}
653653
}
@@ -657,21 +657,21 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
657657
fn encode_mutability(rbml_w: &mut Encoder,
658658
m: ast::Mutability) {
659659
match m {
660-
ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); }
661-
ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); }
660+
ast::MutImmutable => { rbml_w.writer.write_all(&[ 'i' as u8 ]); }
661+
ast::MutMutable => { rbml_w.writer.write_all(&[ 'm' as u8 ]); }
662662
}
663663
}
664664
}
665665

666666
fn encode_item_sort(rbml_w: &mut Encoder, sort: char) {
667667
rbml_w.start_tag(tag_item_trait_item_sort);
668-
rbml_w.writer.write(&[ sort as u8 ]);
668+
rbml_w.writer.write_all(&[ sort as u8 ]);
669669
rbml_w.end_tag();
670670
}
671671

672672
fn encode_parent_sort(rbml_w: &mut Encoder, sort: char) {
673673
rbml_w.start_tag(tag_item_trait_parent_sort);
674-
rbml_w.writer.write(&[ sort as u8 ]);
674+
rbml_w.writer.write_all(&[ sort as u8 ]);
675675
rbml_w.end_tag();
676676
}
677677

@@ -680,7 +680,7 @@ fn encode_provided_source(rbml_w: &mut Encoder,
680680
for source in source_opt.iter() {
681681
rbml_w.start_tag(tag_item_method_provided_source);
682682
let s = def_to_string(*source);
683-
rbml_w.writer.write(s.as_bytes());
683+
rbml_w.writer.write_all(s.as_bytes());
684684
rbml_w.end_tag();
685685
}
686686
}
@@ -927,7 +927,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
927927
rbml_w.start_tag(tag_method_argument_name);
928928
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
929929
let name = token::get_ident(path1.node);
930-
rbml_w.writer.write(name.get().as_bytes());
930+
rbml_w.writer.write_all(name.get().as_bytes());
931931
}
932932
rbml_w.end_tag();
933933
}
@@ -1647,7 +1647,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16471647
ast::MetaWord(ref name) => {
16481648
rbml_w.start_tag(tag_meta_item_word);
16491649
rbml_w.start_tag(tag_meta_item_name);
1650-
rbml_w.writer.write(name.get().as_bytes());
1650+
rbml_w.writer.write_all(name.get().as_bytes());
16511651
rbml_w.end_tag();
16521652
rbml_w.end_tag();
16531653
}
@@ -1656,10 +1656,10 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16561656
ast::LitStr(ref value, _) => {
16571657
rbml_w.start_tag(tag_meta_item_name_value);
16581658
rbml_w.start_tag(tag_meta_item_name);
1659-
rbml_w.writer.write(name.get().as_bytes());
1659+
rbml_w.writer.write_all(name.get().as_bytes());
16601660
rbml_w.end_tag();
16611661
rbml_w.start_tag(tag_meta_item_value);
1662-
rbml_w.writer.write(value.get().as_bytes());
1662+
rbml_w.writer.write_all(value.get().as_bytes());
16631663
rbml_w.end_tag();
16641664
rbml_w.end_tag();
16651665
}
@@ -1669,7 +1669,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16691669
ast::MetaList(ref name, ref items) => {
16701670
rbml_w.start_tag(tag_meta_item_list);
16711671
rbml_w.start_tag(tag_meta_item_name);
1672-
rbml_w.writer.write(name.get().as_bytes());
1672+
rbml_w.writer.write_all(name.get().as_bytes());
16731673
rbml_w.end_tag();
16741674
for inner_item in items.iter() {
16751675
encode_meta_item(rbml_w, &**inner_item);
@@ -1801,7 +1801,7 @@ fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) {
18011801
rbml_w.end_tag();
18021802

18031803
rbml_w.start_tag(tag_native_libraries_name);
1804-
rbml_w.writer.write(lib.as_bytes());
1804+
rbml_w.writer.write_all(lib.as_bytes());
18051805
rbml_w.end_tag();
18061806

18071807
rbml_w.end_tag();
@@ -1981,29 +1981,29 @@ fn encode_crate_dep(rbml_w: &mut Encoder,
19811981
dep: decoder::CrateDep) {
19821982
rbml_w.start_tag(tag_crate_dep);
19831983
rbml_w.start_tag(tag_crate_dep_crate_name);
1984-
rbml_w.writer.write(dep.name.as_bytes());
1984+
rbml_w.writer.write_all(dep.name.as_bytes());
19851985
rbml_w.end_tag();
19861986
rbml_w.start_tag(tag_crate_dep_hash);
1987-
rbml_w.writer.write(dep.hash.as_str().as_bytes());
1987+
rbml_w.writer.write_all(dep.hash.as_str().as_bytes());
19881988
rbml_w.end_tag();
19891989
rbml_w.end_tag();
19901990
}
19911991

19921992
fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) {
19931993
rbml_w.start_tag(tag_crate_hash);
1994-
rbml_w.writer.write(hash.as_str().as_bytes());
1994+
rbml_w.writer.write_all(hash.as_str().as_bytes());
19951995
rbml_w.end_tag();
19961996
}
19971997

19981998
fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) {
19991999
rbml_w.start_tag(tag_crate_crate_name);
2000-
rbml_w.writer.write(crate_name.as_bytes());
2000+
rbml_w.writer.write_all(crate_name.as_bytes());
20012001
rbml_w.end_tag();
20022002
}
20032003

20042004
fn encode_crate_triple(rbml_w: &mut Encoder, triple: &str) {
20052005
rbml_w.start_tag(tag_crate_triple);
2006-
rbml_w.writer.write(triple.as_bytes());
2006+
rbml_w.writer.write_all(triple.as_bytes());
20072007
rbml_w.end_tag();
20082008
}
20092009

@@ -2017,7 +2017,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
20172017
cstore::RequireStatic => "s",
20182018
})).to_string())
20192019
}).collect::<Vec<String>>();
2020-
rbml_w.writer.write(s.connect(",").as_bytes());
2020+
rbml_w.writer.write_all(s.connect(",").as_bytes());
20212021
}
20222022
None => {}
20232023
}

Diff for: src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub type abbrev_map<'tcx> = RefCell<FnvHashMap<Ty<'tcx>, ty_abbrev>>;
5151

5252
pub fn enc_ty<'a, 'tcx>(w: &mut SeekableMemWriter, cx: &ctxt<'a, 'tcx>, t: Ty<'tcx>) {
5353
match cx.abbrevs.borrow_mut().get(&t) {
54-
Some(a) => { w.write(a.s.as_bytes()); return; }
54+
Some(a) => { w.write_all(a.s.as_bytes()); return; }
5555
None => {}
5656
}
5757
let pos = w.tell().unwrap();

Diff for: src/librustc_trans/back/link.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,7 @@ fn link_rlib<'a>(sess: &'a Session,
586586
// the same filename for metadata (stomping over one another)
587587
let tmpdir = TempDir::new("rustc").ok().expect("needs a temp dir");
588588
let metadata = tmpdir.path().join(METADATA_FILENAME);
589-
match fs::File::create(&metadata).write(&trans.metadata
590-
[]) {
589+
match fs::File::create(&metadata).write_all(&trans.metadata[]) {
591590
Ok(..) => {}
592591
Err(e) => {
593592
sess.err(&format!("failed to write {}: {}",
@@ -674,10 +673,10 @@ fn write_rlib_bytecode_object_v1<T: Writer>(writer: &mut T,
674673
-> ::std::old_io::IoResult<()> {
675674
let bc_data_deflated_size: u64 = bc_data_deflated.len() as u64;
676675

677-
try! { writer.write(RLIB_BYTECODE_OBJECT_MAGIC) };
676+
try! { writer.write_all(RLIB_BYTECODE_OBJECT_MAGIC) };
678677
try! { writer.write_le_u32(1) };
679678
try! { writer.write_le_u64(bc_data_deflated_size) };
680-
try! { writer.write(&bc_data_deflated[]) };
679+
try! { writer.write_all(&bc_data_deflated[]) };
681680

682681
let number_of_bytes_written_so_far =
683682
RLIB_BYTECODE_OBJECT_MAGIC.len() + // magic id

Diff for: src/librustdoc/html/render.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ fn render_sources(cx: &mut Context,
626626
/// Writes the entire contents of a string to a destination, not attempting to
627627
/// catch any errors.
628628
fn write(dst: Path, contents: &[u8]) -> old_io::IoResult<()> {
629-
File::create(&dst).write(contents)
629+
File::create(&dst).write_all(contents)
630630
}
631631

632632
/// Makes a directory on the filesystem, failing the task if an error occurs and

Diff for: src/libstd/failure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ thread_local! {
2727
}
2828

2929
impl Writer for Stdio {
30-
fn write(&mut self, bytes: &[u8]) -> IoResult<()> {
30+
fn write_all(&mut self, bytes: &[u8]) -> IoResult<()> {
3131
let _ = self.write_bytes(bytes);
3232
Ok(())
3333
}

0 commit comments

Comments
 (0)