diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/ref-cast/src/layout.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/ref-cast/src/layout.rs')
| -rw-r--r-- | vendor/ref-cast/src/layout.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/ref-cast/src/layout.rs b/vendor/ref-cast/src/layout.rs new file mode 100644 index 00000000..55f91f8c --- /dev/null +++ b/vendor/ref-cast/src/layout.rs @@ -0,0 +1,60 @@ +use core::mem; + +#[doc(hidden)] +pub struct Layout<T: ?Sized>(T); + +#[doc(hidden)] +pub trait LayoutUnsized<T: ?Sized> { + const SIZE: usize = usize::MAX; + const ALIGN: usize = usize::MAX; +} + +impl<T: ?Sized> LayoutUnsized<T> for Layout<T> {} + +impl<T> Layout<T> { + pub const SIZE: usize = mem::size_of::<T>(); + pub const ALIGN: usize = mem::align_of::<T>(); +} + +#[doc(hidden)] +#[inline] +pub fn assert_layout<Outer: ?Sized, Inner: ?Sized>( + name: &'static str, + outer_size: usize, + inner_size: usize, + outer_align: usize, + inner_align: usize, +) { + if outer_size != inner_size { + #[cfg(no_intrinsic_type_name)] + panic!( + "unexpected size in cast to {}: {} != {}", + name, outer_size, inner_size, + ); + #[cfg(not(no_intrinsic_type_name))] + panic!( + "unexpected size in cast from {} to {}: {} != {}", + core::any::type_name::<Inner>(), + core::any::type_name::<Outer>(), + inner_size, + outer_size, + ); + } + if outer_align != inner_align { + #[cfg(no_intrinsic_type_name)] + panic!( + "unexpected alignment in cast to {}: {} != {}", + name, outer_align, inner_align, + ); + #[cfg(not(no_intrinsic_type_name))] + panic!( + "unexpected alignment in cast from {} to {}: {} != {}", + core::any::type_name::<Inner>(), + core::any::type_name::<Outer>(), + inner_align, + outer_align, + ); + } + #[cfg(not(no_intrinsic_type_name))] + let _ = name; +} |
