]> git.lizzy.rs Git - rust.git/commitdiff
Rename `fmt::Writer` to `fmt::Write`
authorChris Wong <lambda.fairy@gmail.com>
Fri, 13 Feb 2015 23:56:32 +0000 (12:56 +1300)
committerChris Wong <lambda.fairy@gmail.com>
Fri, 13 Feb 2015 23:56:32 +0000 (12:56 +1300)
This brings it in line with its namesake in `std::io`.

[breaking-change]

src/libcollections/fmt.rs
src/libcollections/string.rs
src/libcore/fmt/float.rs
src/libcore/fmt/mod.rs
src/libserialize/json.rs
src/libstd/io/mod.rs
src/libstd/old_io/mod.rs
src/libstd/rt/unwind.rs
src/libstd/rt/util.rs
src/test/run-pass/colorful-write-macros.rs
src/test/run-pass/ifmt.rs

index 8f02f9fd580fafb2b7874a1fbb5f84e6361f7793..a2273fe875539672e28865244ed2e980b007d8e9 100644 (file)
 //!
 //! impl fmt::Display for Vector2D {
 //!     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-//!         // The `f` value implements the `Writer` trait, which is what the
+//!         // The `f` value implements the `Write` trait, which is what the
 //!         // write! macro is expecting. Note that this formatting ignores the
 //!         // various flags provided to format strings.
 //!         write!(f, "({}, {})", self.x, self.y)
 
 #![stable(feature = "rust1", since = "1.0.0")]
 
-pub use core::fmt::{Formatter, Result, Writer, rt};
+pub use core::fmt::{Formatter, Result, Write, rt};
 pub use core::fmt::{Show, String, Octal, Binary};
 pub use core::fmt::{Display, Debug};
 pub use core::fmt::{LowerHex, UpperHex, Pointer};
index 63483d30dd202a46e3fbbedd95646bcb55a3c14c..69fd28d1723685067d77df6a650b693f6f7b09c2 100644 (file)
@@ -950,7 +950,7 @@ pub trait ToString {
 impl<T: fmt::Display + ?Sized> ToString for T {
     #[inline]
     fn to_string(&self) -> String {
-        use core::fmt::Writer;
+        use core::fmt::Write;
         let mut buf = String::new();
         let _ = buf.write_fmt(format_args!("{}", self));
         buf.shrink_to_fit();
@@ -984,7 +984,7 @@ fn as_slice<'b>(&'b self) -> &'b str {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl fmt::Writer for String {
+impl fmt::Write for String {
     #[inline]
     fn write_str(&mut self, s: &str) -> fmt::Result {
         self.push_str(s);
index 25bb959b9b3aa9db02d12d0dbc894c151077555f..56b2c2a798370516e46088ddca0eabf18ddf5b24 100644 (file)
@@ -314,7 +314,7 @@ struct Filler<'a> {
                 end: &'a mut uint,
             }
 
-            impl<'a> fmt::Writer for Filler<'a> {
+            impl<'a> fmt::Write for Filler<'a> {
                 fn write_str(&mut self, s: &str) -> fmt::Result {
                     slice::bytes::copy_memory(&mut self.buf[(*self.end)..],
                                               s.as_bytes());
index f940300a26945cf84ed29536f217ec28a4f5fb9e..09733df35398f910f512ee28d8d5f8b62ca81cf6 100644 (file)
@@ -57,14 +57,14 @@ pub mod rt {
 /// A collection of methods that are required to format a message into a stream.
 ///
 /// This trait is the type which this modules requires when formatting
-/// information. This is similar to the standard library's `io::Writer` trait,
+/// information. This is similar to the standard library's `io::Write` trait,
 /// but it is only intended for use in libcore.
 ///
 /// This trait should generally not be implemented by consumers of the standard
-/// library. The `write!` macro accepts an instance of `io::Writer`, and the
-/// `io::Writer` trait is favored over implementing this trait.
+/// library. The `write!` macro accepts an instance of `io::Write`, and the
+/// `io::Write` trait is favored over implementing this trait.
 #[stable(feature = "rust1", since = "1.0.0")]
-pub trait Writer {
+pub trait Write {
     /// Writes a slice of bytes into this writer, returning whether the write
     /// succeeded.
     ///
@@ -85,12 +85,12 @@ pub trait Writer {
     #[stable(feature = "rust1", since = "1.0.0")]
     fn write_fmt(&mut self, args: Arguments) -> Result {
         // This Adapter is needed to allow `self` (of type `&mut
-        // Self`) to be cast to a FormatWriter (below) without
+        // Self`) to be cast to a Write (below) without
         // requiring a `Sized` bound.
         struct Adapter<'a,T: ?Sized +'a>(&'a mut T);
 
-        impl<'a, T: ?Sized> Writer for Adapter<'a, T>
-            where T: Writer
+        impl<'a, T: ?Sized> Write for Adapter<'a, T>
+            where T: Write
         {
             fn write_str(&mut self, s: &str) -> Result {
                 self.0.write_str(s)
@@ -116,7 +116,7 @@ pub struct Formatter<'a> {
     width: Option<uint>,
     precision: Option<uint>,
 
-    buf: &'a mut (Writer+'a),
+    buf: &'a mut (Write+'a),
     curarg: slice::Iter<'a, ArgumentV1<'a>>,
     args: &'a [ArgumentV1<'a>],
 }
@@ -367,7 +367,7 @@ pub trait UpperExp {
 ///   * output - the buffer to write output to
 ///   * args - the precompiled arguments generated by `format_args!`
 #[stable(feature = "rust1", since = "1.0.0")]
-pub fn write(output: &mut Writer, args: Arguments) -> Result {
+pub fn write(output: &mut Write, args: Arguments) -> Result {
     let mut formatter = Formatter {
         flags: 0,
         width: None,
index daa358647d8e6bec3bcea870fb089d3f74217046..d79a31718555357fc8a06df0a8872388e0ed202e 100644 (file)
@@ -371,7 +371,7 @@ fn from_error(err: fmt::Error) -> EncoderError { EncoderError::FmtError(err) }
 pub type EncodeResult = Result<(), EncoderError>;
 pub type DecodeResult<T> = Result<T, DecoderError>;
 
-fn escape_str(wr: &mut fmt::Writer, v: &str) -> EncodeResult {
+fn escape_str(wr: &mut fmt::Write, v: &str) -> EncodeResult {
     try!(wr.write_str("\""));
 
     let mut start = 0;
@@ -433,14 +433,14 @@ fn escape_str(wr: &mut fmt::Writer, v: &str) -> EncodeResult {
     Ok(())
 }
 
-fn escape_char(writer: &mut fmt::Writer, v: char) -> EncodeResult {
+fn escape_char(writer: &mut fmt::Write, v: char) -> EncodeResult {
     let mut buf = [0; 4];
     let n = v.encode_utf8(&mut buf).unwrap();
     let buf = unsafe { str::from_utf8_unchecked(&buf[..n]) };
     escape_str(writer, buf)
 }
 
-fn spaces(wr: &mut fmt::Writer, mut n: uint) -> EncodeResult {
+fn spaces(wr: &mut fmt::Write, mut n: uint) -> EncodeResult {
     const BUF: &'static str = "                ";
 
     while n >= BUF.len() {
@@ -464,14 +464,14 @@ fn fmt_number_or_null(v: f64) -> string::String {
 
 /// A structure for implementing serialization to JSON.
 pub struct Encoder<'a> {
-    writer: &'a mut (fmt::Writer+'a),
+    writer: &'a mut (fmt::Write+'a),
     is_emitting_map_key: bool,
 }
 
 impl<'a> Encoder<'a> {
     /// Creates a new JSON encoder whose output will be written to the writer
     /// specified.
-    pub fn new(writer: &'a mut fmt::Writer) -> Encoder<'a> {
+    pub fn new(writer: &'a mut fmt::Write) -> Encoder<'a> {
         Encoder { writer: writer, is_emitting_map_key: false, }
     }
 }
@@ -709,7 +709,7 @@ fn emit_map_elt_val<F>(&mut self, _idx: uint, f: F) -> EncodeResult where
 /// Another encoder for JSON, but prints out human-readable JSON instead of
 /// compact data
 pub struct PrettyEncoder<'a> {
-    writer: &'a mut (fmt::Writer+'a),
+    writer: &'a mut (fmt::Write+'a),
     curr_indent: uint,
     indent: uint,
     is_emitting_map_key: bool,
@@ -717,7 +717,7 @@ pub struct PrettyEncoder<'a> {
 
 impl<'a> PrettyEncoder<'a> {
     /// Creates a new encoder whose output will be written to the specified writer
-    pub fn new(writer: &'a mut fmt::Writer) -> PrettyEncoder<'a> {
+    pub fn new(writer: &'a mut fmt::Write) -> PrettyEncoder<'a> {
         PrettyEncoder {
             writer: writer,
             curr_indent: 0,
@@ -2527,7 +2527,7 @@ struct FormatShim<'a, 'b: 'a> {
     inner: &'a mut fmt::Formatter<'b>,
 }
 
-impl<'a, 'b> fmt::Writer for FormatShim<'a, 'b> {
+impl<'a, 'b> fmt::Write for FormatShim<'a, 'b> {
     fn write_str(&mut self, s: &str) -> fmt::Result {
         match self.inner.write_str(s) {
             Ok(_) => Ok(()),
index 2668baba095b875f7436d5ff675827f577be8518..89c45f60d1ca8640e312fc6f1cbcec4dd62a5d94 100644 (file)
@@ -381,14 +381,14 @@ fn write_all(&mut self, mut buf: &[u8]) -> Result<()> {
     ///
     /// This function will return any I/O error reported while formatting.
     fn write_fmt(&mut self, fmt: fmt::Arguments) -> Result<()> {
-        // Create a shim which translates a Writer to a fmt::Writer and saves
+        // Create a shim which translates a Write to a fmt::Write and saves
         // off I/O errors. instead of discarding them
         struct Adaptor<'a, T: ?Sized + 'a> {
             inner: &'a mut T,
             error: Result<()>,
         }
 
-        impl<'a, T: Write + ?Sized> fmt::Writer for Adaptor<'a, T> {
+        impl<'a, T: Write + ?Sized> fmt::Write for Adaptor<'a, T> {
             fn write_str(&mut self, s: &str) -> fmt::Result {
                 match self.inner.write_all(s.as_bytes()) {
                     Ok(()) => Ok(()),
index 94f4af8e558ade482e80a2872861178f9509cd9d..cf930ae736c854ab0c7946594b1de616675a49bf 100644 (file)
@@ -1023,14 +1023,14 @@ fn flush(&mut self) -> IoResult<()> { Ok(()) }
     ///
     /// This function will return any I/O error reported while formatting.
     fn write_fmt(&mut self, fmt: fmt::Arguments) -> IoResult<()> {
-        // Create a shim which translates a Writer to a fmt::Writer and saves
+        // Create a shim which translates a Writer to a fmt::Write and saves
         // off I/O errors. instead of discarding them
         struct Adaptor<'a, T: ?Sized +'a> {
             inner: &'a mut T,
             error: IoResult<()>,
         }
 
-        impl<'a, T: ?Sized + Writer> fmt::Writer for Adaptor<'a, T> {
+        impl<'a, T: ?Sized + Writer> fmt::Write for Adaptor<'a, T> {
             fn write_str(&mut self, s: &str) -> fmt::Result {
                 match self.inner.write_all(s.as_bytes()) {
                     Ok(()) => Ok(()),
index 659e787a9ff8f00e9a4e1731bc3668388316ca6e..6abe920e1eab1d501c6f40e0316f44ced7866dc8 100644 (file)
@@ -496,7 +496,7 @@ extern "C" fn inner(
 #[inline(never)] #[cold]
 #[stable(since = "1.0.0", feature = "rust1")]
 pub fn begin_unwind_fmt(msg: fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
-    use fmt::Writer;
+    use fmt::Write;
 
     // We do two allocations here, unfortunately. But (a) they're
     // required with the current scheme, and (b) we don't handle
index bb57d19ed2666ae45d172b64edfd0fea9488e96b..d445c29902801fc9175489759fe1306299adf7b3 100644 (file)
@@ -110,7 +110,7 @@ pub fn write_bytes(&mut self, data: &[u8]) {
     }
 }
 
-impl fmt::Writer for Stdio {
+impl fmt::Write for Stdio {
     fn write_str(&mut self, data: &str) -> fmt::Result {
         self.write_bytes(data.as_bytes());
         Ok(()) // yes, we're lying
@@ -122,13 +122,13 @@ pub fn dumb_print(args: fmt::Arguments) {
 }
 
 pub fn abort(args: fmt::Arguments) -> ! {
-    use fmt::Writer;
+    use fmt::Write;
 
     struct BufWriter<'a> {
         buf: &'a mut [u8],
         pos: uint,
     }
-    impl<'a> fmt::Writer for BufWriter<'a> {
+    impl<'a> fmt::Write for BufWriter<'a> {
         fn write_str(&mut self, bytes: &str) -> fmt::Result {
             let left = &mut self.buf[self.pos..];
             let to_write = &bytes.as_bytes()[..cmp::min(bytes.len(), left.len())];
index bcb2e492041509a95e899f16f1b97ffebd822772..841aaa94e9b552e9f4de847450136245e7dff80e 100644 (file)
@@ -21,7 +21,7 @@ struct Foo<'a> {
 
 struct Bar;
 
-impl fmt::Writer for Bar {
+impl fmt::Write for Bar {
     fn write_str(&mut self, _: &str) -> fmt::Result {
         Ok(())
     }
@@ -39,7 +39,7 @@ fn main() {
 
     let mut s = Bar;
     {
-        use std::fmt::Writer;
+        use std::fmt::Write;
         write!(&mut s, "test");
     }
 }
index 5d157d875fa4dbec76c3d25e5853c5c21da5e5f3..e5aade792edf01bd1a20a4f75aff9394cd8e12da 100644 (file)
@@ -165,9 +165,9 @@ pub fn main() {
 }
 
 // Basic test to make sure that we can invoke the `write!` macro with an
-// io::Writer instance.
+// fmt::Write instance.
 fn test_write() {
-    use std::fmt::Writer;
+    use std::fmt::Write;
     let mut buf = String::new();
     write!(&mut buf, "{}", 3);
     {
@@ -194,7 +194,7 @@ fn test_print() {
 // Just make sure that the macros are defined, there's not really a lot that we
 // can do with them just yet (to test the output)
 fn test_format_args() {
-    use std::fmt::Writer;
+    use std::fmt::Write;
     let mut buf = String::new();
     {
         let w = &mut buf;