Fix conversion of empty vectors to Bytes

Closes #340
This commit is contained in:
Steven Fackler
2019-12-12 08:33:07 -08:00
committed by Sean McArthur
parent a7fc5274ad
commit 17a8ac91e0
+7
View File
@@ -709,6 +709,13 @@ impl From<&'static str> for Bytes {
impl From<Vec<u8>> for Bytes {
fn from(vec: Vec<u8>) -> Bytes {
// into_boxed_slice doesn't return a heap allocation for empty vectors,
// so the pointer isn't aligned enough for the KIND_VEC stashing to
// work.
if vec.is_empty() {
return Bytes::new();
}
let slice = vec.into_boxed_slice();
let len = slice.len();
let ptr = slice.as_ptr();