Skip to content

Commit

Permalink
Vec makes no guarantees about its memory layout
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrobbel committed May 14, 2021
1 parent 3b98f5b commit a95d324
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,8 @@ impl<T, const A: usize> From<Vec<T>> for Buffer<T, A>
where
T: Primitive,
{
fn from(mut vec: Vec<T>) -> Self {
// todo(mb): is this a safe assumption?
match Layout::array::<T>(vec.capacity()) {
Ok(vec_layout) if vec_layout == layout::<T, A>(vec.capacity()) => Self {
ptr: unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) },
len: vec.len(),
},
_ => Self::from_slice(&vec),
}
fn from(vec: Vec<T>) -> Self {
Self::from_slice(&vec)
}
}

Expand Down

0 comments on commit a95d324

Please sign in to comment.