Skip to content

Commit

Permalink
Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
zachs18 committed Mar 2, 2024
1 parent d3d625d commit e8d1579
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
//! `bytemuck = { version = "VERSION_YOU_ARE_USING", features =
//! ["extern_crate_alloc"]}`

use self::sealed::BoxBytesOf;

use super::*;
#[cfg(target_has_atomic = "ptr")]
use alloc::sync::Arc;
Expand Down Expand Up @@ -782,9 +780,9 @@ impl<T: AnyBitPattern> sealed::FromBoxBytes for T {
) -> Result<Box<Self>, (PodCastError, BoxBytes)> {
let layout = Layout::new::<T>();
if bytes.layout.align() != layout.align() {
return Err((PodCastError::AlignmentMismatch, bytes));
Err((PodCastError::AlignmentMismatch, bytes))
} else if bytes.layout.size() != layout.size() {
return Err((PodCastError::SizeMismatch, bytes));
Err((PodCastError::SizeMismatch, bytes))
} else {
let (ptr, _) = bytes.into_raw_parts();
// SAFETY: See BoxBytes type invariant.
Expand All @@ -799,11 +797,11 @@ impl<T: AnyBitPattern> sealed::FromBoxBytes for [T] {
) -> Result<Box<Self>, (PodCastError, BoxBytes)> {
let single_layout = Layout::new::<T>();
if bytes.layout.align() != single_layout.align() {
return Err((PodCastError::AlignmentMismatch, bytes));
Err((PodCastError::AlignmentMismatch, bytes))
} else if single_layout.size() == 0 {
return Err((PodCastError::SizeMismatch, bytes));
Err((PodCastError::SizeMismatch, bytes))
} else if bytes.layout.size() % single_layout.size() != 0 {
return Err((PodCastError::OutputSliceWouldHaveSlop, bytes));
Err((PodCastError::OutputSliceWouldHaveSlop, bytes))
} else {
let (ptr, layout) = bytes.into_raw_parts();
let length = layout.size() / single_layout.size();
Expand Down

0 comments on commit e8d1579

Please sign in to comment.