mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-11 00:00:23 +02:00
committed by
Sean McArthur
parent
a7fc5274ad
commit
17a8ac91e0
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user