You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FromBytes::insert_vec_from_bytes is like FromZeros::insert_vec_zeroed, but accepts bytes: &[u8] to copy instead of an additional: usize zeroed elements to insert. It's an optimization of:
if bytes.len().checked_rem(size_of::<T>()).unwrap_or(bytes.len()) != 0{returnErr(/* bytes.len() is not a multiple of the size of T */);}let additional = bytes.len().checked_div(size_of::<T>()).unwrap_or(0);T::insert_vec_zeroed(&mut values, position, additional)?;// The panic should be optimized away due to the above rem check.
values[position..position + additional].as_mut_bytes().copy_from_slice(bytes);
It should not have a zeroing memory step.
The capacity * size_of::<T>() of the returned Vec<T> should match the size of the input to ensure into_boxed_slice doesn't need to realloc.
bytes does not need to be aligned, same as read_from_bytes.
Note that if T is a ZST, then the only valid input for bytes is &[], which is a no-op.
extend_vec_from_bytes is also included in this design, with no position parameter.
FromBytes::new_vec_from_bytes(bytes: &[u8]) copies into a new Vec<Self>
FromBytes::insert_vec_from_bytes
is likeFromZeros::insert_vec_zeroed
, but acceptsbytes: &[u8]
to copy instead of anadditional: usize
zeroed elements to insert. It's an optimization of:size_of::<T>()
of the returnedVec<T>
should match the size of the input to ensureinto_boxed_slice
doesn't need to realloc.bytes
does not need to be aligned, same asread_from_bytes
.bytes
is&[]
, which is a no-op.extend_vec_from_bytes
is also included in this design, with noposition
parameter.FromBytes::new_vec_from_bytes(bytes: &[u8])
copies into a newVec<Self>
position > v.len()
givenFromZeros::insert_vec_zeroed
both panics and returnsResult
#2242?Err
return type?The text was updated successfully, but these errors were encountered: