pub struct Layout<Size: IsSize, Alignment: IsAlignment> { /* private fields */ }Expand description
Combination of size and alignment.
This is the type to use where a IsLayout generic is required.
Unlike the std::alloc::Layout, this type is for layouts known at compile time.
Additionally, this type doesn’t require size to be a multiple of alignment.
The layout given to a dungeon_cell type determines the types it can store.
To find the layout for a given set of types the
layout_for!() macro can be used.
§Examples
use dungeon_cell::layout::{Layout, Size, Alignment};
type Test = Layout<Size<4>, Alignment<2>>;
assert_eq!(Test::size(), 4);
assert_eq!(Test::alignment(), 2);Implementations§
Source§impl<Size: IsSize, Alignment: IsAlignment> Layout<Size, Alignment>
impl<Size: IsSize, Alignment: IsAlignment> Layout<Size, Alignment>
Sourcepub const fn is_layout_of<T>() -> bool
pub const fn is_layout_of<T>() -> bool
Check if this layout exactly matches the layout for T.
§Examples
use dungeon_cell::layout::{Layout, Size, Alignment};
type TestLayout = Layout<Size<4>, Alignment<4>>;
assert!(TestLayout::is_layout_of::<i32>());
assert!(!TestLayout::is_layout_of::<i16>());Sourcepub const fn alignment() -> usize
pub const fn alignment() -> usize
Alignment in bytes.
This is the value of Alignment::VALUE.
§Examples
use dungeon_cell::layout_for;
assert_eq!(<layout_for!(String)>::alignment(), 8);Sourcepub const fn to_std_layout() -> Result<Layout, LayoutError>
pub const fn to_std_layout() -> Result<Layout, LayoutError>
Create a std::alloc::Layout with the size and alignment of this layout.
This function is available on no_std.
§Examples
use dungeon_cell::layout_for;
use std::alloc::Layout;
let l: Layout = <layout_for!(String)>::to_std_layout().unwrap();
assert_eq!(l.size(), 24);
assert_eq!(l.align(), 8);Sourcepub const fn can_store<T>() -> bool
pub const fn can_store<T>() -> bool
Check if memory with this layout would allow a T to be stored.
This checks that the size of T is equal or less than Self::size(),
and that the alignment of T is equal or less than Self::alignment().
§Examples
use dungeon_cell::layout_for;
type LayoutI32 = layout_for!(i32);
assert!(LayoutI32::can_store::<u8>());
assert!(LayoutI32::can_store::<u16>());
assert!(LayoutI32::can_store::<i32>());
assert!(!LayoutI32::can_store::<String>());Sourcepub fn assert_can_store<T>()
pub fn assert_can_store<T>()
Assert memory with this layout can store a value of T.
This checks that the size of T is equal or less than Self::size(),
and that the alignment of T is equal or less than Self::alignment().
Unsafe code can use the above if this function returns.
This function uses the assert system in compile_time
which means by default it will cause a compile time error if the assertion fails.
§Examples
use dungeon_cell::layout_for;
// a i16 is smaller than a i32
<layout_for!(i32)>::assert_can_store::<i16>();use dungeon_cell::layout_for;
// a i32 is bigger than a i16
<layout_for!(i16)>::assert_can_store::<i32>();Sourcepub const fn const_assert_can_store<T>()
pub const fn const_assert_can_store<T>()
Const form of Self::assert_can_store().
Prefer using Self::assert_can_store() if possible because it can give
better error messages.
§Examples
use dungeon_cell::layout_for;
const fn test() {
// a i16 is smaller than a i32
<layout_for!(i32)>::const_assert_can_store::<i16>();
}
test();use dungeon_cell::layout_for;
const fn test() {
// a i32 is bigger than a i16
<layout_for!(i16)>::const_assert_can_store::<i32>();
}
test();Trait Implementations§
impl<Size: Copy + IsSize, Alignment: Copy + IsAlignment> Copy for Layout<Size, Alignment>
Auto Trait Implementations§
impl<Size, Alignment> Freeze for Layout<Size, Alignment>
impl<Size, Alignment> RefUnwindSafe for Layout<Size, Alignment>
impl<Size, Alignment> Send for Layout<Size, Alignment>
impl<Size, Alignment> Sync for Layout<Size, Alignment>
impl<Size, Alignment> Unpin for Layout<Size, Alignment>
impl<Size, Alignment> UnwindSafe for Layout<Size, Alignment>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Dynamic<Bound<Send, Sync, Copy, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, Sync, Copy, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, Copy, Clone, __, __>> for T
impl<T> Dynamic<Bound<Send, Sync, Copy, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, Copy, __, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, Sync, Copy, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, Copy, __, __, __>> for T
impl<T> Dynamic<Bound<Send, Sync, Copy, __, __, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, __, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, Sync, __, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, __, Clone, __, __>> for T
impl<T> Dynamic<Bound<Send, Sync, __, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, __, __, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, Sync, __, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, Sync, __, __, __, __>> for T
impl<T> Dynamic<Bound<Send, Sync, __, __, __, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, Copy, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, __, Copy, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, Copy, Clone, __, __>> for T
impl<T> Dynamic<Bound<Send, __, Copy, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, Copy, __, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, __, Copy, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, Copy, __, __, __>> for T
impl<T> Dynamic<Bound<Send, __, Copy, __, __, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, __, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, __, __, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, __, Clone, __, __>> for T
impl<T> Dynamic<Bound<Send, __, __, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, __, __, Unpin, __>> for T
impl<T> Dynamic<Bound<Send, __, __, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<Send, __, __, __, __, __>> for Twhere
T: Send,
impl<T> Dynamic<Bound<Send, __, __, __, __, __>> for Twhere
T: Send,
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, Copy, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<__, Sync, Copy, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, Copy, Clone, __, __>> for T
impl<T> Dynamic<Bound<__, Sync, Copy, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, Copy, __, Unpin, __>> for T
impl<T> Dynamic<Bound<__, Sync, Copy, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, Copy, __, __, __>> for T
impl<T> Dynamic<Bound<__, Sync, Copy, __, __, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, __, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<__, Sync, __, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, __, Clone, __, __>> for T
impl<T> Dynamic<Bound<__, Sync, __, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, __, __, Unpin, __>> for T
impl<T> Dynamic<Bound<__, Sync, __, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, Sync, __, __, __, __>> for Twhere
T: Sync,
impl<T> Dynamic<Bound<__, Sync, __, __, __, __>> for Twhere
T: Sync,
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, Copy, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<__, __, Copy, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, Copy, Clone, __, __>> for T
impl<T> Dynamic<Bound<__, __, Copy, Clone, __, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, Copy, __, Unpin, __>> for T
impl<T> Dynamic<Bound<__, __, Copy, __, Unpin, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, Copy, __, __, __>> for Twhere
T: Copy,
impl<T> Dynamic<Bound<__, __, Copy, __, __, __>> for Twhere
T: Copy,
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, __, Clone, Unpin, __>> for T
impl<T> Dynamic<Bound<__, __, __, Clone, Unpin, __>> for T
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, __, Clone, __, __>> for Twhere
T: Clone,
impl<T> Dynamic<Bound<__, __, __, Clone, __, __>> for Twhere
T: Clone,
Source§unsafe fn clone_unchecked(this: &T) -> T
unsafe fn clone_unchecked(this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, __, __, Unpin, __>> for Twhere
T: Unpin,
impl<T> Dynamic<Bound<__, __, __, __, Unpin, __>> for Twhere
T: Unpin,
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read moreSource§impl<T> Dynamic<Bound<__, __, __, __, __, __>> for T
impl<T> Dynamic<Bound<__, __, __, __, __, __>> for T
Source§unsafe fn clone_unchecked(_this: &T) -> T
unsafe fn clone_unchecked(_this: &T) -> T
Self::clone(). Read moreSource§unsafe fn debug_unchecked(
_this: &T,
_f: &mut Formatter<'_>,
) -> Result<(), Error>
unsafe fn debug_unchecked( _this: &T, _f: &mut Formatter<'_>, ) -> Result<(), Error>
Self::debug(). Read more