Skip to content

Add MemWriter::from_vec #18329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/libstd/io/mem.rs
Original file line number Diff line number Diff line change
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