Skip to content

Commit

Permalink
fix #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebind committed Feb 2, 2018
1 parent 298bf06 commit 9e9f1fb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ impl From<Buffer> for Vec<u8> {
let len = buffer.copy_to(&mut slice);

unsafe {
Vec::from_raw_parts(slice.as_mut_ptr(), len, slice.len())
let vec = Vec::from_raw_parts(slice.as_mut_ptr(), len, slice.len());
mem::forget(slice);
vec
}
}
}
Expand Down Expand Up @@ -291,4 +293,17 @@ mod tests {
buffer.copy_to(&mut out);
assert!(&out == b"hello world");
}

#[test]
fn vec_from_buffer() {
let mut buffer = Buffer::new();
let bytes = b"hello world";
buffer.push(bytes);

assert!(buffer.len() == bytes.len());

let vec = Vec::from(buffer);

assert!(&vec == bytes);
}
}

0 comments on commit 9e9f1fb

Please sign in to comment.