diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-11-11 16:01:29 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-11-18 01:09:46 -0500 |
| commit | 85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8 (patch) | |
| tree | 578802f9e774e104b1a271b92946208e0e0a0675 /src/libstd/fmt.rs | |
| parent | 9c96a79a74f10bed18b031ce0ac4126c56d6cfb3 (diff) | |
| download | rust-85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8.tar.gz rust-85c2c2e38ce7c606fac1e9c8fa9d2ab71b35c8c8.zip | |
implement Writer for Vec<u8>
The trait has an obvious, sensible implementation directly on vectors so the MemWriter wrapper is unnecessary. This will halt the trend towards providing all of the vector methods on MemWriter along with eliminating the noise caused by conversions between the two types. It also provides the useful default Writer methods on Vec<u8>. After the type is removed and code has been migrated, it would make sense to add a new implementation of MemWriter with seeking support. The simple use cases can be covered with vectors alone, and ones with the need for seeks can use a new MemWriter implementation.
Diffstat (limited to 'src/libstd/fmt.rs')
| -rw-r--r-- | src/libstd/fmt.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libstd/fmt.rs b/src/libstd/fmt.rs index eb81935a8c9..e140ddba723 100644 --- a/src/libstd/fmt.rs +++ b/src/libstd/fmt.rs @@ -256,7 +256,7 @@ actually invoking the `write` function defined in this module. Example usage is: # #![allow(unused_must_use)] use std::io; -let mut w = io::MemWriter::new(); +let mut w = Vec::new(); write!(&mut w as &mut io::Writer, "Hello {}!", "world"); ``` @@ -415,6 +415,7 @@ use io::Writer; use io; use result::{Ok, Err}; use string; +use vec::Vec; pub use core::fmt::{Formatter, Result, FormatWriter, rt}; pub use core::fmt::{Show, Bool, Char, Signed, Unsigned, Octal, Binary}; @@ -443,10 +444,10 @@ pub use core::fmt::{argument, argumentstr, argumentuint}; /// let s = format_args!(fmt::format, "Hello, {}!", "world"); /// assert_eq!(s, "Hello, world!".to_string()); /// ``` -pub fn format(args: &Arguments) -> string::String{ - let mut output = io::MemWriter::new(); - let _ = write!(&mut output, "{}", args); - string::String::from_utf8(output.unwrap()).unwrap() +pub fn format(args: &Arguments) -> string::String { + let mut output = Vec::new(); + let _ = write!(&mut output as &mut Writer, "{}", args); + string::String::from_utf8(output).unwrap() } impl<'a> Writer for Formatter<'a> { |
