about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-27 09:07:49 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-27 15:12:30 -0700
commit287df9e0ebf5cb5c855f69d4b617ab5df5824f98 (patch)
treec2f3ad55e70ed111c2e338010263c28510d2f964 /src/libstd/io
parented7f4a8da4f628646e70c16690c1c1cd98d5e039 (diff)
parentbed5a7d92a90f067e933fb7e4f2d656330f88f11 (diff)
downloadrust-287df9e0ebf5cb5c855f69d4b617ab5df5824f98.tar.gz
rust-287df9e0ebf5cb5c855f69d4b617ab5df5824f98.zip
rollup merge of #18329 : sfackler/memwriter-clear
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/mem.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libstd/io/mem.rs b/src/libstd/io/mem.rs
index f86ae05d623..dd4a3e05935 100644
--- a/src/libstd/io/mem.rs
+++ b/src/libstd/io/mem.rs
@@ -22,7 +22,7 @@ use slice;
 use slice::AsSlice;
 use vec::Vec;
 
-static BUF_CAPACITY: uint = 128;
+const BUF_CAPACITY: uint = 128;
 
 fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> {
     // compute offset as signed and clamp to prevent overflow
@@ -71,7 +71,12 @@ impl MemWriter {
     /// the internal buffer.
     #[inline]
     pub fn with_capacity(n: uint) -> MemWriter {
-        MemWriter { buf: Vec::with_capacity(n) }
+        MemWriter::from_vec(Vec::with_capacity(n))
+    }
+    /// Create a new `MemWriter` that will append to an existing `Vec`.
+    #[inline]
+    pub fn from_vec(buf: Vec<u8>) -> MemWriter {
+        MemWriter { buf: buf }
     }
 
     /// Acquires an immutable reference to the underlying buffer of this