Skip to content

Commit bc9084b

Browse files
committed
Rename fmt::Writer to fmt::Write
This brings it in line with its namesake in `std::io`. [breaking-change]
1 parent cf636c2 commit bc9084b

File tree

11 files changed

+35
-35
lines changed

11 files changed

+35
-35
lines changed

src/libcollections/fmt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
//!
180180
//! impl fmt::Display for Vector2D {
181181
//! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
182-
//! // The `f` value implements the `Writer` trait, which is what the
182+
//! // The `f` value implements the `Write` trait, which is what the
183183
//! // write! macro is expecting. Note that this formatting ignores the
184184
//! // various flags provided to format strings.
185185
//! write!(f, "({}, {})", self.x, self.y)
@@ -403,7 +403,7 @@
403403
404404
#![stable(feature = "rust1", since = "1.0.0")]
405405

406-
pub use core::fmt::{Formatter, Result, Writer, rt};
406+
pub use core::fmt::{Formatter, Result, Write, rt};
407407
pub use core::fmt::{Show, String, Octal, Binary};
408408
pub use core::fmt::{Display, Debug};
409409
pub use core::fmt::{LowerHex, UpperHex, Pointer};

src/libcollections/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ pub trait ToString {
950950
impl<T: fmt::Display + ?Sized> ToString for T {
951951
#[inline]
952952
fn to_string(&self) -> String {
953-
use core::fmt::Writer;
953+
use core::fmt::Write;
954954
let mut buf = String::new();
955955
let _ = buf.write_fmt(format_args!("{}", self));
956956
buf.shrink_to_fit();
@@ -984,7 +984,7 @@ impl<'a> Str for CowString<'a> {
984984
}
985985

986986
#[stable(feature = "rust1", since = "1.0.0")]
987-
impl fmt::Writer for String {
987+
impl fmt::Write for String {
988988
#[inline]
989989
fn write_str(&mut self, s: &str) -> fmt::Result {
990990
self.push_str(s);

src/libcore/fmt/float.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
314314
end: &'a mut uint,
315315
}
316316

317-
impl<'a> fmt::Writer for Filler<'a> {
317+
impl<'a> fmt::Write for Filler<'a> {
318318
fn write_str(&mut self, s: &str) -> fmt::Result {
319319
slice::bytes::copy_memory(&mut self.buf[(*self.end)..],
320320
s.as_bytes());

src/libcore/fmt/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ pub struct Error;
5757
/// A collection of methods that are required to format a message into a stream.
5858
///
5959
/// This trait is the type which this modules requires when formatting
60-
/// information. This is similar to the standard library's `io::Writer` trait,
60+
/// information. This is similar to the standard library's `io::Write` trait,
6161
/// but it is only intended for use in libcore.
6262
///
6363
/// This trait should generally not be implemented by consumers of the standard
64-
/// library. The `write!` macro accepts an instance of `io::Writer`, and the
65-
/// `io::Writer` trait is favored over implementing this trait.
64+
/// library. The `write!` macro accepts an instance of `io::Write`, and the
65+
/// `io::Write` trait is favored over implementing this trait.
6666
#[stable(feature = "rust1", since = "1.0.0")]
67-
pub trait Writer {
67+
pub trait Write {
6868
/// Writes a slice of bytes into this writer, returning whether the write
6969
/// succeeded.
7070
///
@@ -85,12 +85,12 @@ pub trait Writer {
8585
#[stable(feature = "rust1", since = "1.0.0")]
8686
fn write_fmt(&mut self, args: Arguments) -> Result {
8787
// This Adapter is needed to allow `self` (of type `&mut
88-
// Self`) to be cast to a FormatWriter (below) without
88+
// Self`) to be cast to a Write (below) without
8989
// requiring a `Sized` bound.
9090
struct Adapter<'a,T: ?Sized +'a>(&'a mut T);
9191

92-
impl<'a, T: ?Sized> Writer for Adapter<'a, T>
93-
where T: Writer
92+
impl<'a, T: ?Sized> Write for Adapter<'a, T>
93+
where T: Write
9494
{
9595
fn write_str(&mut self, s: &str) -> Result {
9696
self.0.write_str(s)
@@ -116,7 +116,7 @@ pub struct Formatter<'a> {
116116
width: Option<uint>,
117117
precision: Option<uint>,
118118

119-
buf: &'a mut (Writer+'a),
119+
buf: &'a mut (Write+'a),
120120
curarg: slice::Iter<'a, ArgumentV1<'a>>,
121121
args: &'a [ArgumentV1<'a>],
122122
}
@@ -367,7 +367,7 @@ pub trait UpperExp {
367367
/// * output - the buffer to write output to
368368
/// * args - the precompiled arguments generated by `format_args!`
369369
#[stable(feature = "rust1", since = "1.0.0")]
370-
pub fn write(output: &mut Writer, args: Arguments) -> Result {
370+
pub fn write(output: &mut Write, args: Arguments) -> Result {
371371
let mut formatter = Formatter {
372372
flags: 0,
373373
width: None,

src/libserialize/json.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl std::error::FromError<fmt::Error> for EncoderError {
371371
pub type EncodeResult = Result<(), EncoderError>;
372372
pub type DecodeResult<T> = Result<T, DecoderError>;
373373

374-
fn escape_str(wr: &mut fmt::Writer, v: &str) -> EncodeResult {
374+
fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult {
375375
try!(wr.write_str("\""));
376376

377377
let mut start = 0;
@@ -433,14 +433,14 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> EncodeResult {
433433
Ok(())
434434
}
435435

436-
fn escape_char(writer: &mut fmt::Writer, v: char) -> EncodeResult {
436+
fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult {
437437
let mut buf = [0; 4];
438438
let n = v.encode_utf8(&mut buf).unwrap();
439439
let buf = unsafe { str::from_utf8_unchecked(&buf[..n]) };
440440
escape_str(writer, buf)
441441
}
442442

443-
fn spaces(wr: &mut fmt::Writer, mut n: uint) -> EncodeResult {
443+
fn spaces(wr: &mut fmt::Write, mut n: uint) -> EncodeResult {
444444
const BUF: &'static str = " ";
445445

446446
while n >= BUF.len() {
@@ -464,14 +464,14 @@ fn fmt_number_or_null(v: f64) -> string::String {
464464

465465
/// A structure for implementing serialization to JSON.
466466
pub struct Encoder<'a> {
467-
writer: &'a mut (fmt::Writer+'a),
467+
writer: &'a mut (fmt::Write+'a),
468468
is_emitting_map_key: bool,
469469
}
470470

471471
impl<'a> Encoder<'a> {
472472
/// Creates a new JSON encoder whose output will be written to the writer
473473
/// specified.
474-
pub fn new(writer: &'a mut fmt::Writer) -> Encoder<'a> {
474+
pub fn new(writer: &'a mut fmt::Write) -> Encoder<'a> {
475475
Encoder { writer: writer, is_emitting_map_key: false, }
476476
}
477477
}
@@ -709,15 +709,15 @@ impl<'a> ::Encoder for Encoder<'a> {
709709
/// Another encoder for JSON, but prints out human-readable JSON instead of
710710
/// compact data
711711
pub struct PrettyEncoder<'a> {
712-
writer: &'a mut (fmt::Writer+'a),
712+
writer: &'a mut (fmt::Write+'a),
713713
curr_indent: uint,
714714
indent: uint,
715715
is_emitting_map_key: bool,
716716
}
717717

718718
impl<'a> PrettyEncoder<'a> {
719719
/// Creates a new encoder whose output will be written to the specified writer
720-
pub fn new(writer: &'a mut fmt::Writer) -> PrettyEncoder<'a> {
720+
pub fn new(writer: &'a mut fmt::Write) -> PrettyEncoder<'a> {
721721
PrettyEncoder {
722722
writer: writer,
723723
curr_indent: 0,
@@ -2527,7 +2527,7 @@ struct FormatShim<'a, 'b: 'a> {
25272527
inner: &'a mut fmt::Formatter<'b>,
25282528
}
25292529

2530-
impl<'a, 'b> fmt::Writer for FormatShim<'a, 'b> {
2530+
impl<'a, 'b> fmt::Write for FormatShim<'a, 'b> {
25312531
fn write_str(&mut self, s: &str) -> fmt::Result {
25322532
match self.inner.write_str(s) {
25332533
Ok(_) => Ok(()),

src/libstd/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -381,14 +381,14 @@ pub trait Write {
381381
///
382382
/// This function will return any I/O error reported while formatting.
383383
fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
384-
// Create a shim which translates a Writer to a fmt::Writer and saves
384+
// Create a shim which translates a Write to a fmt::Write and saves
385385
// off I/O errors. instead of discarding them
386386
struct Adaptor<'a, T: ?Sized + 'a> {
387387
inner: &'a mut T,
388388
error: Result<()>,
389389
}
390390

391-
impl<'a, T: Write + ?Sized> fmt::Writer for Adaptor<'a, T> {
391+
impl<'a, T: Write + ?Sized> fmt::Write for Adaptor<'a, T> {
392392
fn write_str(&mut self, s: &str) -> fmt::Result {
393393
match self.inner.write_all(s.as_bytes()) {
394394
Ok(()) => Ok(()),

src/libstd/old_io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1023,14 +1023,14 @@ pub trait Writer {
10231023
///
10241024
/// This function will return any I/O error reported while formatting.
10251025
fn write_fmt(&mut self, fmt: fmt::Arguments) -> IoResult<()> {
1026-
// Create a shim which translates a Writer to a fmt::Writer and saves
1026+
// Create a shim which translates a Writer to a fmt::Write and saves
10271027
// off I/O errors. instead of discarding them
10281028
struct Adaptor<'a, T: ?Sized +'a> {
10291029
inner: &'a mut T,
10301030
error: IoResult<()>,
10311031
}
10321032

1033-
impl<'a, T: ?Sized + Writer> fmt::Writer for Adaptor<'a, T> {
1033+
impl<'a, T: ?Sized + Writer> fmt::Write for Adaptor<'a, T> {
10341034
fn write_str(&mut self, s: &str) -> fmt::Result {
10351035
match self.inner.write_all(s.as_bytes()) {
10361036
Ok(()) => Ok(()),

src/libstd/rt/unwind.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub extern fn rust_begin_unwind(msg: fmt::Arguments,
496496
#[inline(never)] #[cold]
497497
#[stable(since = "1.0.0", feature = "rust1")]
498498
pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
499-
use fmt::Writer;
499+
use fmt::Write;
500500

501501
// We do two allocations here, unfortunately. But (a) they're
502502
// required with the current scheme, and (b) we don't handle

src/libstd/rt/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Stdio {
110110
}
111111
}
112112

113-
impl fmt::Writer for Stdio {
113+
impl fmt::Write for Stdio {
114114
fn write_str(&mut self, data: &str) -> fmt::Result {
115115
self.write_bytes(data.as_bytes());
116116
Ok(()) // yes, we're lying
@@ -122,13 +122,13 @@ pub fn dumb_print(args: fmt::Arguments) {
122122
}
123123

124124
pub fn abort(args: fmt::Arguments) -> ! {
125-
use fmt::Writer;
125+
use fmt::Write;
126126

127127
struct BufWriter<'a> {
128128
buf: &'a mut [u8],
129129
pos: uint,
130130
}
131-
impl<'a> fmt::Writer for BufWriter<'a> {
131+
impl<'a> fmt::Write for BufWriter<'a> {
132132
fn write_str(&mut self, bytes: &str) -> fmt::Result {
133133
let left = &mut self.buf[self.pos..];
134134
let to_write = &bytes.as_bytes()[..cmp::min(bytes.len(), left.len())];

src/test/run-pass/colorful-write-macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Foo<'a> {
2121

2222
struct Bar;
2323

24-
impl fmt::Writer for Bar {
24+
impl fmt::Write for Bar {
2525
fn write_str(&mut self, _: &str) -> fmt::Result {
2626
Ok(())
2727
}
@@ -39,7 +39,7 @@ fn main() {
3939

4040
let mut s = Bar;
4141
{
42-
use std::fmt::Writer;
42+
use std::fmt::Write;
4343
write!(&mut s, "test");
4444
}
4545
}

src/test/run-pass/ifmt.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ pub fn main() {
165165
}
166166

167167
// Basic test to make sure that we can invoke the `write!` macro with an
168-
// io::Writer instance.
168+
// fmt::Write instance.
169169
fn test_write() {
170-
use std::fmt::Writer;
170+
use std::fmt::Write;
171171
let mut buf = String::new();
172172
write!(&mut buf, "{}", 3);
173173
{
@@ -194,7 +194,7 @@ fn test_print() {
194194
// Just make sure that the macros are defined, there's not really a lot that we
195195
// can do with them just yet (to test the output)
196196
fn test_format_args() {
197-
use std::fmt::Writer;
197+
use std::fmt::Write;
198198
let mut buf = String::new();
199199
{
200200
let w = &mut buf;

0 commit comments

Comments
 (0)