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/io/mem.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/io/mem.rs')
| -rw-r--r-- | src/libstd/io/mem.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs index 66ae88cfe51..21de6c2013d 100644 --- a/src/libstd/io/mem.rs +++ b/src/libstd/io/mem.rs @@ -12,6 +12,8 @@ //! Readers and Writers for in-memory buffers +#![allow(deprecated)] + use cmp::min; use option::None; use result::{Err, Ok}; @@ -41,6 +43,14 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> } } +impl Writer for Vec<u8> { + #[inline] + fn write(&mut self, buf: &[u8]) -> IoResult<()> { + self.push_all(buf); + Ok(()) + } +} + /// Writes to an owned, growable byte vector /// /// # Example @@ -54,6 +64,7 @@ fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> /// /// assert_eq!(w.unwrap(), vec!(0, 1, 2)); /// ``` +#[deprecated = "use the Vec<u8> Writer implementation directly"] #[deriving(Clone)] pub struct MemWriter { buf: Vec<u8>, |
