Skip to content

Commit 5d836cd

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 3a07f85 commit 5d836cd

Some content is hidden

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

41 files changed

+229
-226
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/libcoretest/fmt/num.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ mod u32 {
170170
use test::Bencher;
171171
use core::fmt::radix;
172172
use std::rand::{weak_rng, Rng};
173-
use std::io::util::NullWriter;
173+
use std::old_io::util::NullWriter;
174174

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

218218
#[bench]
219219
fn format_bin(b: &mut Bencher) {

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
}
@@ -636,17 +636,17 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
636636
// Encode the base self type.
637637
match *explicit_self {
638638
ty::StaticExplicitSelfCategory => {
639-
rbml_w.writer.write(&[ 's' as u8 ]);
639+
rbml_w.writer.write_all(&[ 's' as u8 ]);
640640
}
641641
ty::ByValueExplicitSelfCategory => {
642-
rbml_w.writer.write(&[ 'v' as u8 ]);
642+
rbml_w.writer.write_all(&[ 'v' as u8 ]);
643643
}
644644
ty::ByBoxExplicitSelfCategory => {
645-
rbml_w.writer.write(&[ '~' as u8 ]);
645+
rbml_w.writer.write_all(&[ '~' as u8 ]);
646646
}
647647
ty::ByReferenceExplicitSelfCategory(_, m) => {
648648
// FIXME(#4846) encode custom lifetime
649-
rbml_w.writer.write(&['&' as u8]);
649+
rbml_w.writer.write_all(&['&' as u8]);
650650
encode_mutability(rbml_w, m);
651651
}
652652
}
@@ -656,21 +656,21 @@ fn encode_explicit_self(rbml_w: &mut Encoder,
656656
fn encode_mutability(rbml_w: &mut Encoder,
657657
m: ast::Mutability) {
658658
match m {
659-
ast::MutImmutable => { rbml_w.writer.write(&[ 'i' as u8 ]); }
660-
ast::MutMutable => { rbml_w.writer.write(&[ 'm' as u8 ]); }
659+
ast::MutImmutable => { rbml_w.writer.write_all(&[ 'i' as u8 ]); }
660+
ast::MutMutable => { rbml_w.writer.write_all(&[ 'm' as u8 ]); }
661661
}
662662
}
663663
}
664664

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

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

@@ -679,7 +679,7 @@ fn encode_provided_source(rbml_w: &mut Encoder,
679679
for source in source_opt.iter() {
680680
rbml_w.start_tag(tag_item_method_provided_source);
681681
let s = def_to_string(*source);
682-
rbml_w.writer.write(s.as_bytes());
682+
rbml_w.writer.write_all(s.as_bytes());
683683
rbml_w.end_tag();
684684
}
685685
}
@@ -926,7 +926,7 @@ fn encode_method_argument_names(rbml_w: &mut Encoder,
926926
rbml_w.start_tag(tag_method_argument_name);
927927
if let ast::PatIdent(_, ref path1, _) = arg.pat.node {
928928
let name = token::get_ident(path1.node);
929-
rbml_w.writer.write(name.get().as_bytes());
929+
rbml_w.writer.write_all(name.get().as_bytes());
930930
}
931931
rbml_w.end_tag();
932932
}
@@ -1646,7 +1646,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16461646
ast::MetaWord(ref name) => {
16471647
rbml_w.start_tag(tag_meta_item_word);
16481648
rbml_w.start_tag(tag_meta_item_name);
1649-
rbml_w.writer.write(name.get().as_bytes());
1649+
rbml_w.writer.write_all(name.get().as_bytes());
16501650
rbml_w.end_tag();
16511651
rbml_w.end_tag();
16521652
}
@@ -1655,10 +1655,10 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16551655
ast::LitStr(ref value, _) => {
16561656
rbml_w.start_tag(tag_meta_item_name_value);
16571657
rbml_w.start_tag(tag_meta_item_name);
1658-
rbml_w.writer.write(name.get().as_bytes());
1658+
rbml_w.writer.write_all(name.get().as_bytes());
16591659
rbml_w.end_tag();
16601660
rbml_w.start_tag(tag_meta_item_value);
1661-
rbml_w.writer.write(value.get().as_bytes());
1661+
rbml_w.writer.write_all(value.get().as_bytes());
16621662
rbml_w.end_tag();
16631663
rbml_w.end_tag();
16641664
}
@@ -1668,7 +1668,7 @@ fn encode_meta_item(rbml_w: &mut Encoder, mi: &ast::MetaItem) {
16681668
ast::MetaList(ref name, ref items) => {
16691669
rbml_w.start_tag(tag_meta_item_list);
16701670
rbml_w.start_tag(tag_meta_item_name);
1671-
rbml_w.writer.write(name.get().as_bytes());
1671+
rbml_w.writer.write_all(name.get().as_bytes());
16721672
rbml_w.end_tag();
16731673
for inner_item in items.iter() {
16741674
encode_meta_item(rbml_w, &**inner_item);
@@ -1800,7 +1800,7 @@ fn encode_native_libraries(ecx: &EncodeContext, rbml_w: &mut Encoder) {
18001800
rbml_w.end_tag();
18011801

18021802
rbml_w.start_tag(tag_native_libraries_name);
1803-
rbml_w.writer.write(lib.as_bytes());
1803+
rbml_w.writer.write_all(lib.as_bytes());
18041804
rbml_w.end_tag();
18051805

18061806
rbml_w.end_tag();
@@ -1975,29 +1975,29 @@ fn encode_crate_dep(rbml_w: &mut Encoder,
19751975
dep: decoder::CrateDep) {
19761976
rbml_w.start_tag(tag_crate_dep);
19771977
rbml_w.start_tag(tag_crate_dep_crate_name);
1978-
rbml_w.writer.write(dep.name.as_bytes());
1978+
rbml_w.writer.write_all(dep.name.as_bytes());
19791979
rbml_w.end_tag();
19801980
rbml_w.start_tag(tag_crate_dep_hash);
1981-
rbml_w.writer.write(dep.hash.as_str().as_bytes());
1981+
rbml_w.writer.write_all(dep.hash.as_str().as_bytes());
19821982
rbml_w.end_tag();
19831983
rbml_w.end_tag();
19841984
}
19851985

19861986
fn encode_hash(rbml_w: &mut Encoder, hash: &Svh) {
19871987
rbml_w.start_tag(tag_crate_hash);
1988-
rbml_w.writer.write(hash.as_str().as_bytes());
1988+
rbml_w.writer.write_all(hash.as_str().as_bytes());
19891989
rbml_w.end_tag();
19901990
}
19911991

19921992
fn encode_crate_name(rbml_w: &mut Encoder, crate_name: &str) {
19931993
rbml_w.start_tag(tag_crate_crate_name);
1994-
rbml_w.writer.write(crate_name.as_bytes());
1994+
rbml_w.writer.write_all(crate_name.as_bytes());
19951995
rbml_w.end_tag();
19961996
}
19971997

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

@@ -2011,7 +2011,7 @@ fn encode_dylib_dependency_formats(rbml_w: &mut Encoder, ecx: &EncodeContext) {
20112011
cstore::RequireStatic => "s",
20122012
})).to_string())
20132013
}).collect::<Vec<String>>();
2014-
rbml_w.writer.write(s.connect(",").as_bytes());
2014+
rbml_w.writer.write_all(s.connect(",").as_bytes());
20152015
}
20162016
None => {}
20172017
}

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)