pub unsafe fn alloc_uninitialized(&self, num: usize) -> &mut [MaybeUninit<T>] {
        let mut chunks = self.chunks.borrow_mut();

        debug_assert!(
            chunks.current.capacity() >= chunks.current.len(),
            "capacity is always greater than or equal to len, so we don't need to worry about underflow"
        );
        if num > chunks.current.capacity() - chunks.current.len() {
            chunks.reserve(num);
        }

        // At this point, the current chunk must have free capacity.
        let next_item_index = chunks.current.len();
        chunks.current.set_len(next_item_index + num);

        // Go through pointers, to make sure we never create a reference to uninitialized T.
        let start = chunks.current.as_mut_ptr().offset(next_item_index as isize);
        let start_uninit = start as *mut MaybeUninit<T>;
        slice::from_raw_parts_mut(start_uninit, num)
    }
/// Allocates space for a given number of values, but doesn't initialize it.
///
/// ## Safety
///
/// After calling this method, the arena considers the elements initialized. If you fail to
/// initialize them (which includes because of panicking during the initialization), the arena
/// will run destructors on the uninitialized memory. Therefore, you must initialize them.
///
/// Considering how easy it is to cause undefined behaviour using this, you're advised to
/// prefer the other (safe) methods, like [`alloc_extend`][Arena::alloc_extend].
///
/// ## Example
///
/// ```rust
/// use std::mem::{self, MaybeUninit};
/// use std::ptr;
/// use typed_arena::Arena;
///
/// // Transmute from MaybeUninit slice to slice of initialized T.
/// // It is a separate function to preserve the lifetime of the reference.
/// unsafe fn transmute_uninit<A>(r: &mut [MaybeUninit<A>]) -> &mut [A] {
///     mem::transmute(r)
/// }
///
/// let arena: Arena<bool> = Arena::new();
/// let slice: &mut [bool];
/// unsafe {
///     let uninitialized = arena.alloc_uninitialized(10);
///     for elem in uninitialized.iter_mut() {
///         ptr::write(elem.as_mut_ptr(), true);
///     }
///     slice = transmute_uninit(uninitialized);
/// }
/// ```
///
/// ## Alternative allocation pattern
///
/// To avoid the problem of dropping assumed to be initialized elements on panic, it is also
/// possible to combine the [`reserve_extend`][Arena::reserve_extend] with
/// [`uninitialized_array`][Arena::uninitialized_array], initialize the elements and confirm
/// them by this method. In such case, when there's a panic during initialization, the already
/// initialized elements would leak but it wouldn't cause UB.
///
/// ```rust
/// use std::mem::{self, MaybeUninit};
/// use std::ptr;
/// use typed_arena::Arena;
///
/// unsafe fn transmute_uninit<A>(r: &mut [MaybeUninit<A>]) -> &mut [A] {
///     mem::transmute(r)
/// }
///
/// const COUNT: usize = 2;
///
/// let arena: Arena<String> = Arena::new();
///
/// arena.reserve_extend(COUNT);
/// let slice: &mut [String];
/// unsafe {
///     // Perform initialization before we claim the memory.
///     let uninitialized = arena.uninitialized_array();
///     assert!((*uninitialized).len() >= COUNT); // Ensured by the reserve_extend
///     for elem in &mut (*uninitialized)[..COUNT] {
///         ptr::write(elem.as_mut_ptr(), "Hello".to_owned());
///     }
///     let addr = (*uninitialized).as_ptr() as usize;
///
///     // The alloc_uninitialized returns the same memory, but "confirms" its allocation.
///     slice = transmute_uninit(arena.alloc_uninitialized(COUNT));
///     assert_eq!(addr, slice.as_ptr() as usize);
///     assert_eq!(slice, &["Hello".to_owned(), "Hello".to_owned()]);
/// }
/// ```
Allocates space for a given number of values, but doesn't initialize it.
Allocates space for a given number of values but doesn ' t initialize it .
pub unsafe fn alloc_uninitialized(&self, num: usize) -> &mut [MaybeUninit<T>] {
        let mut chunks = self.chunks.borrow_mut();
        debug_assert!(
            chunks.current.capacity() >= chunks.current.len(),
            "capacity is always greater than or equal to len, so we don't need to worry about underflow"
        );
        if num > chunks.current.capacity() - chunks.current.len() {
            chunks.reserve(num);
        }
        // At this point, the current chunk must have free capacity.
        let next_item_index = chunks.current.len();
        chunks.current.set_len(next_item_index + num);
        // Go through pointers, to make sure we never create a reference to uninitialized T.
        let start = chunks.current.as_mut_ptr().offset(next_item_index as isize);
        let start_uninit = start as *mut MaybeUninit<T>;
        slice::from_raw_parts_mut(start_uninit, num)
    }
pub unsafe fn alloc_uninitialized ( & self , num : usize ) -> & mut [ MaybeUninit < T > ] { let mut chunks = self . chunks . borrow_mut ( ) ; debug_assert ! ( chunks current capacity ( ) chunks current len ( ) " " ) ; if num > chunks . current . capacity ( ) - chunks . current . len ( ) { chunks . reserve ( num ) ; } // At this point, the current chunk must have free capacity. let next_item_index = chunks . current . len ( ) ; chunks . current . set_len ( next_item_index + num ) ; // Go through pointers, to make sure we never create a reference to uninitialized T. let start = chunks . current . as_mut_ptr ( ) . offset ( next_item_index as isize ) ; let start_uninit = start as * mut MaybeUninit < T > ; slice :: from_raw_parts_mut ( start_uninit , num ) }
Allocates space for a given number of values, but doesn't initialize it.
Allocates space for a given number of values but doesn ' t initialize it .
&self
num
usize
&self
num
usize
safety
After calling this method, the arena considers the elements initialized. If you fail to
initialize them (which includes because of panicking during the initialization), the arena
will run destructors on the uninitialized memory. Therefore, you must initialize them.

Considering how easy it is to cause undefined behaviour using this, you're advised to
prefer the other (safe) methods, like [`alloc_extend`][Arena::alloc_extend].
After calling this method the arena considers the elements initialized . If you fail to initialize them ( which includes because of panicking during the initialization ) the arena will run destructors on the uninitialized memory . Therefore you must initialize them . Considering how easy it is to cause undefined behaviour using this you ' re advised to prefer the other ( safe ) methods like [ ` alloc_extend ` ] [ Arena :: alloc_extend ] .
example
```rust
use std::mem::{self, MaybeUninit};
use std::ptr;
use typed_arena::Arena.

Transmute from MaybeUninit slice to slice of initialized T.
It is a separate function to preserve the lifetime of the reference.
unsafe fn transmute_uninit(r: &mut [MaybeUninit]) -> &mut [A] {
mem::transmute(r)
}

let arena: Arena = Arena::new();
let slice: &mut [bool];
unsafe {
let uninitialized = arena.alloc_uninitialized(10);
for elem in uninitialized.iter_mut() {
ptr::write(elem.as_mut_ptr(), true);
}
slice = transmute_uninit(uninitialized);
}
```
` ` ` rust use std :: mem :: { self MaybeUninit } ; use std :: ptr ; use typed_arena :: Arena . Transmute from MaybeUninit slice to slice of initialized T . It is a separate function to preserve the lifetime of the reference . unsafe fn transmute_uninit ( r : &mut [ MaybeUninit ] ) - > &mut [ A ] { mem :: transmute ( r ) } let arena : Arena = Arena :: new () ; let slice : &mut [ bool ] ; unsafe { let uninitialized = arena . alloc_uninitialized ( 10 ) ; for elem in uninitialized . iter_mut () { ptr :: write ( elem . as_mut_ptr () true ) ; } slice = transmute_uninit ( uninitialized ) ; } ` ` `
alternative allocation pattern
To avoid the problem of dropping assumed to be initialized elements on panic, it is also
possible to combine the [`reserve_extend`][Arena::reserve_extend] with
[`uninitialized_array`][Arena::uninitialized_array], initialize the elements and confirm
them by this method. In such case, when there's a panic during initialization, the already
initialized elements would leak but it wouldn't cause UB.

```rust
use std::mem::{self, MaybeUninit};
use std::ptr;
use typed_arena::Arena.

unsafe fn transmute_uninit(r: &mut [MaybeUninit]) -> &mut [A] {
mem::transmute(r)
}

const COUNT: usize = 2.

let arena: Arena = Arena::new().

arena.reserve_extend(COUNT);
let slice: &mut [String];
unsafe {
Perform initialization before we claim the memory.
let uninitialized = arena.uninitialized_array();
assert!((*uninitialized).len() >= COUNT); // Ensured by the reserve_extend
for elem in &mut (*uninitialized)[..COUNT] {
ptr::write(elem.as_mut_ptr(), "Hello".to_owned());
}
let addr = (*uninitialized).as_ptr() as usize.

The alloc_uninitialized returns the same memory, but "confirms" its allocation.
slice = transmute_uninit(arena.alloc_uninitialized(COUNT));
assert_eq!(addr, slice.as_ptr() as usize);
assert_eq!(slice, &["Hello".to_owned(), "Hello".to_owned()]);
}
```
To avoid the problem of dropping assumed to be initialized elements on panic it is also possible to combine the [ ` reserve_extend ` ] [ Arena :: reserve_extend ] with [ ` uninitialized_array ` ] [ Arena :: uninitialized_array ] initialize the elements and confirm them by this method . In such case when there ' s a panic during initialization the already initialized elements would leak but it wouldn ' t cause UB . ` ` ` rust use std :: mem :: { self MaybeUninit } ; use std :: ptr ; use typed_arena :: Arena . unsafe fn transmute_uninit ( r : &mut [ MaybeUninit ] ) - > &mut [ A ] { mem :: transmute ( r ) } const COUNT : usize = 2 . let arena : Arena = Arena :: new () . arena . reserve_extend ( COUNT ) ; let slice : &mut [ String ] ; unsafe { Perform initialization before we claim the memory . let uninitialized = arena . uninitialized_array () ; assert! (( * uninitialized ) . len () > = COUNT ) ; // Ensured by the reserve_extend for elem in &mut ( * uninitialized ) [ .. COUNT ] { ptr :: write ( elem . as_mut_ptr () " Hello " . to_owned () ) ; } let addr = ( * uninitialized ) . as_ptr () as usize . The alloc_uninitialized returns the same memory but " confirms " its allocation . slice = transmute_uninit ( arena . alloc_uninitialized ( COUNT )) ; assert_eq! ( addr slice . as_ptr () as usize ) ; assert_eq! ( slice & [ " Hello " . to_owned () " Hello " . to_owned () ] ) ; } ` ` `