Skip to content

Commit

Permalink
Add MemWriter::from_vec
Browse files Browse the repository at this point in the history
  • Loading branch information
sfackler committed Oct 26, 2014
1 parent 80e5fe1 commit bed5a7d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/libstd/io/mem.rs
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bed5a7d

Please sign in to comment.