This brings it in line with its namesake in `std::io`.
[breaking-change]
//!
//! 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};
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();
}
#[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);
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());
/// 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.
///
#[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)
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>],
}
/// * 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,
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;
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() {
/// 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, }
}
}
/// 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,
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,
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(()),
///
/// 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(()),
///
/// 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(()),
#[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
}
}
-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
}
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())];
struct Bar;
-impl fmt::Writer for Bar {
+impl fmt::Write for Bar {
fn write_str(&mut self, _: &str) -> fmt::Result {
Ok(())
}
let mut s = Bar;
{
- use std::fmt::Writer;
+ use std::fmt::Write;
write!(&mut s, "test");
}
}
}
// 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);
{
// 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;