Skip to content

Commit bed5a7d

Browse files
committed
Add MemWriter::from_vec
1 parent 80e5fe1 commit bed5a7d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/libstd/io/mem.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use slice;
2222
use slice::AsSlice;
2323
use vec::Vec;
2424

25-
static BUF_CAPACITY: uint = 128;
25+
const BUF_CAPACITY: uint = 128;
2626

2727
fn combine(seek: SeekStyle, cur: uint, end: uint, offset: i64) -> IoResult<u64> {
2828
// compute offset as signed and clamp to prevent overflow
@@ -71,7 +71,12 @@ impl MemWriter {
7171
/// the internal buffer.
7272
#[inline]
7373
pub fn with_capacity(n: uint) -> MemWriter {
74-
MemWriter { buf: Vec::with_capacity(n) }
74+
MemWriter::from_vec(Vec::with_capacity(n))
75+
}
76+
/// Create a new `MemWriter` that will append to an existing `Vec`.
77+
#[inline]
78+
pub fn from_vec(buf: Vec<u8>) -> MemWriter {
79+
MemWriter { buf: buf }
7580
}
7681

7782
/// Acquires an immutable reference to the underlying buffer of this

0 commit comments

Comments
 (0)