use const_utils::cond;
use core::alloc::Layout;
use core::mem::{align_of, size_of};
use std::alloc::{alloc, dealloc};
pub unsafe fn allocate<T>(layout: Layout) -> *mut T {
alloc(layout) as *mut T
}
pub unsafe fn deallocate<T>(ptr: *mut T, layout: Layout) {
dealloc(ptr as *mut u8, layout);
}
pub const fn size_align<T>(repeat: usize) -> (usize, usize) {
let align = align_of::<T>();
let size = size_of::<T>();
(size * repeat, align)
}
pub const fn aligned_size<T>(align: usize) -> usize {
let size = size_of::<T>();
let off_by = size % align;
let adjusted_size = size + align - off_by;
cond(off_by == 0, size, adjusted_size)
}