pub fn new(chunk: &'static mut [u8]) -> Self {
        unsafe {
            assert_eq!(size_of::<SlabFreeList>(), 16);

            assert!(
                16 <= Self::SLAB_SIZE,
                "Slab allocator's type T size, {} bytes, is smaller than 16 bytes",
                Self::SLAB_SIZE,
            );
            assert_eq!(Self::SLAB_SIZE & 0xf, 0);

            let free_size = chunk.len() - chunk.len() % Self::SLAB_SIZE;
            Self {
                free_size,
                free_list: {
                    let mut free_list = ptr::NonNull::new(chunk.as_mut_ptr() as _).unwrap();
                    *free_list.as_mut() = SlabFreeList {
                        size: free_size,
                        next: None,
                    };
                    free_list
                },
                _phantom: PhantomData,
            }
        }
    }
/// Creates a new slab allocator from a page allocator.
///
/// # Safety
/// `chunk_addr` has to be a pointer to a chunk of 2 MiB.
Creates a new slab allocator from a page allocator.
Creates a new slab allocator from a page allocator .
pub fn new(chunk: &'static mut [u8]) -> Self {
        unsafe {
            assert_eq!(size_of::<SlabFreeList>(), 16);
            assert!(
                16 <= Self::SLAB_SIZE,
                "Slab allocator's type T size, {} bytes, is smaller than 16 bytes",
                Self::SLAB_SIZE,
            );
            assert_eq!(Self::SLAB_SIZE & 0xf, 0);
            let free_size = chunk.len() - chunk.len() % Self::SLAB_SIZE;
            Self {
                free_size,
                free_list: {
                    let mut free_list = ptr::NonNull::new(chunk.as_mut_ptr() as _).unwrap();
                    *free_list.as_mut() = SlabFreeList {
                        size: free_size,
                        next: None,
                    };
                    free_list
                },
                _phantom: PhantomData,
            }
        }
    }
pub fn new ( chunk : & ' static mut [ u8 ] ) -> Self { unsafe { assert_eq ! ( size_of SlabFreeList ( ) 16 ) ; assert ! ( 16 Self SLAB_SIZE " " Self SLAB_SIZE ) ; assert_eq ! ( Self SLAB_SIZE 0xf 0 ) ; let free_size = chunk . len ( ) - chunk . len ( ) % Self :: SLAB_SIZE ; Self { free_size , free_list : { let mut free_list = ptr :: NonNull :: new ( chunk . as_mut_ptr ( ) as _ ) . unwrap ( ) ; * free_list . as_mut ( ) = SlabFreeList { size : free_size , next : None , } ; free_list } , _phantom : PhantomData , } } }
Creates a new slab allocator from a page allocator.
Creates a new slab allocator from a page allocator .
chunk
&'static mut [u8]
chunk
&'static mut [u8]
safety
`chunk_addr` has to be a pointer to a chunk of 2 MiB.
` chunk_addr ` has to be a pointer to a chunk of 2 MiB .