Rename fmt::Writer to fmt::Write

This brings it in line with its namesake in `std::io`.

[breaking-change]
This commit is contained in:
Chris Wong 2015-02-14 12:56:32 +13:00
parent cf636c233d
commit bc9084b9b7
11 changed files with 35 additions and 35 deletions

View File

@ -179,7 +179,7 @@
//!
//! 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)
@ -403,7 +403,7 @@
#![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};

View 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 @@ impl<'a> Str for CowString<'a> {
}
#[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);

View File

@ -314,7 +314,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
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());

View File

@ -57,14 +57,14 @@ pub struct Error;
/// 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,

View File

@ -371,7 +371,7 @@ impl std::error::FromError<fmt::Error> for EncoderError {
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 @@ impl<'a> ::Encoder for Encoder<'a> {
/// 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(()),

View File

@ -381,14 +381,14 @@ pub trait Write {
///
/// 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(()),

View File

@ -1023,14 +1023,14 @@ pub trait Writer {
///
/// 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(()),

View File

@ -496,7 +496,7 @@ pub extern fn rust_begin_unwind(msg: fmt::Arguments,
#[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

View File

@ -110,7 +110,7 @@ impl Stdio {
}
}
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())];

View 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");
}
}

View 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;