/// Reallocates a block previously suitable for holding `n_old`
/// instances of `T`, returning a block suitable for holding
/// `n_new` instances of `T`.
///
/// Captures a common usage pattern for allocators.
///
/// The returned block is suitable for passing to the
/// `alloc`/`realloc` methods of this allocator.
///
/// # Safety
///
/// This function is unsafe because undefined behavior can result
/// if the caller does not ensure all of the following:
///
/// * `ptr` must be currently allocated via this allocator,
///
/// * the layout of `[T; n_old]` must *fit* that block of memory.
///
/// # Errors
///
/// Returning `Err` indicates that either memory is exhausted or
/// `[T; n_new]` does not meet allocator's size or alignment
/// constraints.
///
/// For zero-sized `T` or `n_new == 0`, may return either of `Ok` or
/// `Err`, but will *not* yield undefined behavior.
///
/// Always returns `Err` on arithmetic overflow.
///
/// Clients wishing to abort computation in response to a
/// reallocation error are encouraged to call the [`handle_alloc_error`] function,
/// rather than directly invoking `panic!` or similar.
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html


Captures a common usage pattern for allocators.

The returned block is suitable for passing to the
`alloc`/`realloc` methods of this allocator.
Captures a common usage pattern for allocators . The returned block is suitable for passing to the ` alloc ` / ` realloc ` methods of this allocator .
unsafe fn realloc_array<T>(&mut self,
                               ptr: NonNull<T>,
                               n_old: usize,
                               n_new: usize) -> Result<NonNull<T>, AllocErr>
        where Self: Sized
    {
        match (Layout::array::<T>(n_old), Layout::array::<T>(n_new)) {
            (Ok(ref k_old), Ok(ref k_new)) if k_old.size() > 0 && k_new.size() > 0 => {
                debug_assert!(k_old.align() == k_new.align());
                self.realloc(ptr.cast(), k_old.clone(), k_new.size()).map(NonNull::cast)
            }
            _ => {
                Err(AllocErr)
            }
        }
    }
unsafe fn realloc_array < T > ( & mut self , ptr : NonNull < T > , n_old : usize , n_new : usize ) -> Result < NonNull < T > , AllocErr > where Self : Sized { match ( Layout :: array :: < T > ( n_old ) , Layout :: array :: < T > ( n_new ) ) { ( Ok ( ref k_old ) , Ok ( ref k_new ) ) if k_old . size ( ) > 0 && k_new . size ( ) > 0 => { debug_assert ! ( k_old align ( ) k_new align ( ) ) ; self . realloc ( ptr . cast ( ) , k_old . clone ( ) , k_new . size ( ) ) . map ( NonNull :: cast ) } _ => { Err ( AllocErr ) } } }
Reallocates a block previously suitable for holding `n_old`
instances of `T`, returning a block suitable for holding
`n_new` instances of `T`.
Reallocates a block previously suitable for holding ` n_old ` instances of ` T ` returning a block suitable for holding ` n_new ` instances of ` T ` .
&mut self
ptr
NonNull<T>
n_old
usize
n_new
usize
safety
This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following.

`ptr` must be currently allocated via this allocator.

the layout of `[T; n_old]` must *fit* that block of memory.
This function is unsafe because undefined behavior can result if the caller does not ensure all of the following . ` ptr ` must be currently allocated via this allocator . the layout of ` [ T ; n_old ] ` must * fit * that block of memory .
errors
Returning `Err` indicates that either memory is exhausted or
`[T; n_new]` does not meet allocator's size or alignment
constraints.

For zero-sized `T` or `n_new == 0`, may return either of `Ok` or
`Err`, but will *not* yield undefined behavior.

Always returns `Err` on arithmetic overflow.

Clients wishing to abort computation in response to a
reallocation error are encouraged to call the [`handle_alloc_error`] function,
rather than directly invoking `panic!` or similar.

[`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
Returning ` Err ` indicates that either memory is exhausted or ` [ T ; n_new ] ` does not meet allocator ' s size or alignment constraints . For zero - sized ` T ` or ` n_new == 0 ` may return either of ` Ok ` or ` Err ` but will * not * yield undefined behavior . Always returns ` Err ` on arithmetic overflow . Clients wishing to abort computation in response to a reallocation error are encouraged to call the [ ` handle_alloc_error ` ] function rather than directly invoking ` panic! ` or similar . [ ` handle_alloc_error ` ] : .. / .. / alloc / alloc / fn . handle_alloc_error . html