Sophie

Sophie

distrib > Mageia > 6 > armv7hl > media > core-updates > by-pkgid > 4e2dbb669434a7691662cb2f0ad38972 > files > 971

rust-doc-1.28.0-1.mga6.armv7hl.rpm

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="API documentation for the Rust `Alloc` trait in crate `core`."><meta name="keywords" content="rust, rustlang, rust-lang, Alloc"><title>core::alloc::Alloc - Rust</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><script src="../../storage.js"></script><link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"></head><body class="rustdoc trait"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu">&#9776;</div><a href='../../core/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a><p class='location'>Trait Alloc</p><div class="sidebar-elems"><div class="block items"><a class="sidebar-title" href="#required-methods">Required Methods</a><div class="sidebar-links"><a href="#tymethod.alloc">alloc</a><a href="#tymethod.dealloc">dealloc</a></div><a class="sidebar-title" href="#provided-methods">Provided Methods</a><div class="sidebar-links"><a href="#method.usable_size">usable_size</a><a href="#method.realloc">realloc</a><a href="#method.alloc_zeroed">alloc_zeroed</a><a href="#method.alloc_excess">alloc_excess</a><a href="#method.realloc_excess">realloc_excess</a><a href="#method.grow_in_place">grow_in_place</a><a href="#method.shrink_in_place">shrink_in_place</a><a href="#method.alloc_one">alloc_one</a><a href="#method.dealloc_one">dealloc_one</a><a href="#method.alloc_array">alloc_array</a><a href="#method.realloc_array">realloc_array</a><a href="#method.dealloc_array">dealloc_array</a></div><a class="sidebar-title" href="#implementors">Implementors</a></div><p class='location'><a href='../index.html'>core</a>::<wbr><a href='index.html'>alloc</a></p><script>window.sidebarCurrent = {name: 'Alloc', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script></div></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!"><img src="../../brush.svg" width="18" alt="Pick another theme!"></button><div id="theme-choices"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form js-only"><div class="search-container"><input class="search-input" name="search" autocomplete="off" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>core</a>::<wbr><a href='index.html'>alloc</a>::<wbr><a class="trait" href=''>Alloc</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version '></span><span id='render-detail'><a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class='inner'>&#x2212;</span>]</a></span><a class='srclink' href='../../src/core/alloc.rs.html#692-1262' title='goto source code'>[src]</a></span></h1><div class="docblock type-decl"><pre class='rust trait'>pub unsafe trait Alloc {
    unsafe fn <a href='#tymethod.alloc' class='fnname'>alloc</a>(&amp;mut self, layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;;
<div class='item-spacer'></div>    unsafe fn <a href='#tymethod.dealloc' class='fnname'>dealloc</a>(&amp;mut self, ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>);

    fn <a href='#method.usable_size' class='fnname'>usable_size</a>(&amp;self, layout: &amp;<a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>) -&gt; (usize, usize) { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.realloc' class='fnname'>realloc</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.alloc_zeroed' class='fnname'>alloc_zeroed</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a><br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.alloc_excess' class='fnname'>alloc_excess</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a><br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/alloc/struct.Excess.html" title="struct core::alloc::Excess">Excess</a>, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.realloc_excess' class='fnname'>realloc_excess</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/alloc/struct.Excess.html" title="struct core::alloc::Excess">Excess</a>, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.grow_in_place' class='fnname'>grow_in_place</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.CannotReallocInPlace.html" title="struct core::alloc::CannotReallocInPlace">CannotReallocInPlace</a>&gt; { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.shrink_in_place' class='fnname'>shrink_in_place</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.CannotReallocInPlace.html" title="struct core::alloc::CannotReallocInPlace">CannotReallocInPlace</a>&gt; { ... }
<div class='item-spacer'></div>    fn <a href='#method.alloc_one' class='fnname'>alloc_one</a>&lt;T&gt;(&amp;mut self) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
    { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.dealloc_one' class='fnname'>dealloc_one</a>&lt;T&gt;(&amp;mut self, ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;)<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
    { ... }
<div class='item-spacer'></div>    fn <a href='#method.alloc_array' class='fnname'>alloc_array</a>&lt;T&gt;(&amp;mut self, n: usize) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
    { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.realloc_array' class='fnname'>realloc_array</a>&lt;T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n_old: usize, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n_new: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
    { ... }
<div class='item-spacer'></div>    unsafe fn <a href='#method.dealloc_array' class='fnname'>dealloc_array</a>&lt;T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;n: usize<br>&nbsp;&nbsp;&nbsp;&nbsp;) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;<br>&nbsp;&nbsp;&nbsp; <span class="where">where<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a></span>,
    { ... }
}</pre></div><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>An implementation of <code>Alloc</code> can allocate, reallocate, and
deallocate arbitrary blocks of data described via <code>Layout</code>.</p>
<p>Some of the methods require that a memory block be <em>currently
allocated</em> via an allocator. This means that:</p>
<ul>
<li>
<p>the starting address for that memory block was previously
returned by a previous call to an allocation method (<code>alloc</code>,
<code>alloc_zeroed</code>, <code>alloc_excess</code>, <code>alloc_one</code>, <code>alloc_array</code>) or
reallocation method (<code>realloc</code>, <code>realloc_excess</code>, or
<code>realloc_array</code>), and</p>
</li>
<li>
<p>the memory block has not been subsequently deallocated, where
blocks are deallocated either by being passed to a deallocation
method (<code>dealloc</code>, <code>dealloc_one</code>, <code>dealloc_array</code>) or by being
passed to a reallocation method (see above) that returns <code>Ok</code>.</p>
</li>
</ul>
<p>A note regarding zero-sized types and zero-sized layouts: many
methods in the <code>Alloc</code> trait state that allocation requests
must be non-zero size, or else undefined behavior can result.</p>
<ul>
<li>
<p>However, some higher-level allocation methods (<code>alloc_one</code>,
<code>alloc_array</code>) are well-defined on zero-sized types and can
optionally support them: it is left up to the implementor
whether to return <code>Err</code>, or to return <code>Ok</code> with some pointer.</p>
</li>
<li>
<p>If an <code>Alloc</code> implementation chooses to return <code>Ok</code> in this
case (i.e. the pointer denotes a zero-sized inaccessible block)
then that returned pointer must be considered &quot;currently
allocated&quot;. On such an allocator, <em>all</em> methods that take
currently-allocated pointers as inputs must accept these
zero-sized pointers, <em>without</em> causing undefined behavior.</p>
</li>
<li>
<p>In other words, if a zero-sized pointer can flow out of an
allocator, then that allocator must likewise accept that pointer
flowing back into its deallocation and reallocation methods.</p>
</li>
</ul>
<p>Some of the methods require that a layout <em>fit</em> a memory block.
What it means for a layout to &quot;fit&quot; a memory block means (or
equivalently, for a memory block to &quot;fit&quot; a layout) is that the
following two conditions must hold:</p>
<ol>
<li>
<p>The block's starting address must be aligned to <code>layout.align()</code>.</p>
</li>
<li>
<p>The block's size must fall in the range <code>[use_min, use_max]</code>, where:</p>
<ul>
<li>
<p><code>use_min</code> is <code>self.usable_size(layout).0</code>, and</p>
</li>
<li>
<p><code>use_max</code> is the capacity that was (or would have been)
returned when (if) the block was allocated via a call to
<code>alloc_excess</code> or <code>realloc_excess</code>.</p>
</li>
</ul>
</li>
</ol>
<p>Note that:</p>
<ul>
<li>
<p>the size of the layout most recently used to allocate the block
is guaranteed to be in the range <code>[use_min, use_max]</code>, and</p>
</li>
<li>
<p>a lower-bound on <code>use_max</code> can be safely approximated by a call to
<code>usable_size</code>.</p>
</li>
<li>
<p>if a layout <code>k</code> fits a memory block (denoted by <code>ptr</code>)
currently allocated via an allocator <code>a</code>, then it is legal to
use that layout to deallocate it, i.e. <code>a.dealloc(ptr, k);</code>.</p>
</li>
</ul>
<h1 id="unsafety" class="section-header"><a href="#unsafety">Unsafety</a></h1>
<p>The <code>Alloc</code> trait is an <code>unsafe</code> trait for a number of reasons, and
implementors must ensure that they adhere to these contracts:</p>
<ul>
<li>
<p>Pointers returned from allocation functions must point to valid memory and
retain their validity until at least the instance of <code>Alloc</code> is dropped
itself.</p>
</li>
<li>
<p><code>Layout</code> queries and calculations in general must be correct. Callers of
this trait are allowed to rely on the contracts defined on each method,
and implementors must ensure such contracts remain true.</p>
</li>
</ul>
<p>Note that this list may get tweaked over time as clarifications are made in
the future.</p>
</div>
            <h2 id='required-methods' class='small-section-header'>
              Required Methods<a href='#required-methods' class='anchor'></a>
            </h2>
            <div class='methods'>
        <h3 id='tymethod.alloc' class='method'><span id='alloc.v' class='invisible'><code>unsafe fn <a href='#tymethod.alloc' class='fnname'>alloc</a>(&amp;mut self, layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Returns a pointer meeting the size and alignment guarantees of
<code>layout</code>.</p>
<p>If this method returns an <code>Ok(addr)</code>, then the <code>addr</code> returned
will be non-null address pointing to a block of storage
suitable for holding an instance of <code>layout</code>.</p>
<p>The returned block of storage may or may not have its contents
initialized. (Extension subtraits might restrict this
behavior, e.g. to ensure initialization to particular sets of
bit patterns.)</p>
<h1 id="safety" class="section-header"><a href="#safety">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure that <code>layout</code> has non-zero size.</p>
<p>(Extension subtraits might provide more specific bounds on
behavior, e.g. guarantee a sentinel address or a null pointer
in response to a zero-size allocation request.)</p>
<h1 id="errors" class="section-header"><a href="#errors">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>layout</code> does not meet allocator's size or alignment
constraints.</p>
<p>Implementations are encouraged to return <code>Err</code> on memory
exhaustion rather than panicking or aborting, but this is not
a strict requirement. (Specifically: it is <em>legal</em> to
implement this trait atop an underlying native allocation
library that aborts on memory exhaustion.)</p>
<p>Clients wishing to abort computation in response to an
allocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='tymethod.dealloc' class='method'><span id='dealloc.v' class='invisible'><code>unsafe fn <a href='#tymethod.dealloc' class='fnname'>dealloc</a>(&amp;mut self, ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>)</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Deallocate the memory referenced by <code>ptr</code>.</p>
<h1 id="safety-1" class="section-header"><a href="#safety-1">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following:</p>
<ul>
<li>
<p><code>ptr</code> must denote a block of memory currently allocated via
this allocator,</p>
</li>
<li>
<p><code>layout</code> must <em>fit</em> that block of memory,</p>
</li>
<li>
<p>In addition to fitting the block of memory <code>layout</code>, the
alignment of the <code>layout</code> must match the alignment used
to allocate that block of memory.</p>
</li>
</ul>
</div></div>
            <h2 id='provided-methods' class='small-section-header'>
              Provided Methods<a href='#provided-methods' class='anchor'></a>
            </h2>
            <div class='methods'>
        <h3 id='method.usable_size' class='method'><span id='usable_size.v' class='invisible'><code>fn <a href='#method.usable_size' class='fnname'>usable_size</a>(&amp;self, layout: &amp;<a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>) -&gt; (usize, usize)</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Returns bounds on the guaranteed usable size of a successful
allocation created with the specified <code>layout</code>.</p>
<p>In particular, if one has a memory block allocated via a given
allocator <code>a</code> and layout <code>k</code> where <code>a.usable_size(k)</code> returns
<code>(l, u)</code>, then one can pass that block to <code>a.dealloc()</code> with a
layout in the size range [l, u].</p>
<p>(All implementors of <code>usable_size</code> must ensure that
<code>l &lt;= k.size() &lt;= u</code>)</p>
<p>Both the lower- and upper-bounds (<code>l</code> and <code>u</code> respectively)
are provided, because an allocator based on size classes could
misbehave if one attempts to deallocate a block without
providing a correct value for its size (i.e., one within the
range <code>[l, u]</code>).</p>
<p>Clients who wish to make use of excess capacity are encouraged
to use the <code>alloc_excess</code> and <code>realloc_excess</code> instead, as
this method is constrained to report conservative values that
serve as valid bounds for <em>all possible</em> allocation method
calls.</p>
<p>However, for clients that do not wish to track the capacity
returned by <code>alloc_excess</code> locally, this method is likely to
produce useful results.</p>
</div><h3 id='method.realloc' class='method'><span id='realloc.v' class='invisible'><code>unsafe fn <a href='#method.realloc' class='fnname'>realloc</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Returns a pointer suitable for holding data described by
a new layout with <code>layout</code>’s alginment and a size given
by <code>new_size</code>. To
accomplish this, this may extend or shrink the allocation
referenced by <code>ptr</code> to fit the new layout.</p>
<p>If this returns <code>Ok</code>, then ownership of the memory block
referenced by <code>ptr</code> has been transferred to this
allocator. The memory may or may not have been freed, and
should be considered unusable (unless of course it was
transferred back to the caller again via the return value of
this method).</p>
<p>If this method returns <code>Err</code>, then ownership of the memory
block has not been transferred to this allocator, and the
contents of the memory block are unaltered.</p>
<h1 id="safety-2" class="section-header"><a href="#safety-2">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following:</p>
<ul>
<li>
<p><code>ptr</code> must be currently allocated via this allocator,</p>
</li>
<li>
<p><code>layout</code> must <em>fit</em> the <code>ptr</code> (see above). (The <code>new_size</code>
argument need not fit it.)</p>
</li>
<li>
<p><code>new_size</code> must be greater than zero.</p>
</li>
<li>
<p><code>new_size</code>, when rounded up to the nearest multiple of <code>layout.align()</code>,
must not overflow (i.e. the rounded value must be less than <code>usize::MAX</code>).</p>
</li>
</ul>
<p>(Extension subtraits might provide more specific bounds on
behavior, e.g. guarantee a sentinel address or a null pointer
in response to a zero-size allocation request.)</p>
<h1 id="errors-1" class="section-header"><a href="#errors-1">Errors</a></h1>
<p>Returns <code>Err</code> only if the new layout
does not meet the allocator's size
and alignment constraints of the allocator, or if reallocation
otherwise fails.</p>
<p>Implementations are encouraged to return <code>Err</code> on memory
exhaustion rather than panicking or aborting, but this is not
a strict requirement. (Specifically: it is <em>legal</em> to
implement this trait atop an underlying native allocation
library that aborts on memory exhaustion.)</p>
<p>Clients wishing to abort computation in response to a
reallocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.alloc_zeroed' class='method'><span id='alloc_zeroed.v' class='invisible'><code>unsafe fn <a href='#method.alloc_zeroed' class='fnname'>alloc_zeroed</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a><br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Behaves like <code>alloc</code>, but also ensures that the contents
are set to zero before being returned.</p>
<h1 id="safety-3" class="section-header"><a href="#safety-3">Safety</a></h1>
<p>This function is unsafe for the same reasons that <code>alloc</code> is.</p>
<h1 id="errors-2" class="section-header"><a href="#errors-2">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>layout</code> does not meet allocator's size or alignment
constraints, just as in <code>alloc</code>.</p>
<p>Clients wishing to abort computation in response to an
allocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.alloc_excess' class='method'><span id='alloc_excess.v' class='invisible'><code>unsafe fn <a href='#method.alloc_excess' class='fnname'>alloc_excess</a>(&amp;mut self, layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/alloc/struct.Excess.html" title="struct core::alloc::Excess">Excess</a>, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Behaves like <code>alloc</code>, but also returns the whole size of
the returned block. For some <code>layout</code> inputs, like arrays, this
may include extra storage usable for additional data.</p>
<h1 id="safety-4" class="section-header"><a href="#safety-4">Safety</a></h1>
<p>This function is unsafe for the same reasons that <code>alloc</code> is.</p>
<h1 id="errors-3" class="section-header"><a href="#errors-3">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>layout</code> does not meet allocator's size or alignment
constraints, just as in <code>alloc</code>.</p>
<p>Clients wishing to abort computation in response to an
allocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.realloc_excess' class='method'><span id='realloc_excess.v' class='invisible'><code>unsafe fn <a href='#method.realloc_excess' class='fnname'>realloc_excess</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/alloc/struct.Excess.html" title="struct core::alloc::Excess">Excess</a>, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Behaves like <code>realloc</code>, but also returns the whole size of
the returned block. For some <code>layout</code> inputs, like arrays, this
may include extra storage usable for additional data.</p>
<h1 id="safety-5" class="section-header"><a href="#safety-5">Safety</a></h1>
<p>This function is unsafe for the same reasons that <code>realloc</code> is.</p>
<h1 id="errors-4" class="section-header"><a href="#errors-4">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>layout</code> does not meet allocator's size or alignment
constraints, just as in <code>realloc</code>.</p>
<p>Clients wishing to abort computation in response to a
reallocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.grow_in_place' class='method'><span id='grow_in_place.v' class='invisible'><code>unsafe fn <a href='#method.grow_in_place' class='fnname'>grow_in_place</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.CannotReallocInPlace.html" title="struct core::alloc::CannotReallocInPlace">CannotReallocInPlace</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Attempts to extend the allocation referenced by <code>ptr</code> to fit <code>new_size</code>.</p>
<p>If this returns <code>Ok</code>, then the allocator has asserted that the
memory block referenced by <code>ptr</code> now fits <code>new_size</code>, and thus can
be used to carry data of a layout of that size and same alignment as
<code>layout</code>. (The allocator is allowed to
expend effort to accomplish this, such as extending the memory block to
include successor blocks, or virtual memory tricks.)</p>
<p>Regardless of what this method returns, ownership of the
memory block referenced by <code>ptr</code> has not been transferred, and
the contents of the memory block are unaltered.</p>
<h1 id="safety-6" class="section-header"><a href="#safety-6">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following:</p>
<ul>
<li>
<p><code>ptr</code> must be currently allocated via this allocator,</p>
</li>
<li>
<p><code>layout</code> must <em>fit</em> the <code>ptr</code> (see above); note the
<code>new_size</code> argument need not fit it,</p>
</li>
<li>
<p><code>new_size</code> must not be less than <code>layout.size()</code>,</p>
</li>
</ul>
<h1 id="errors-5" class="section-header"><a href="#errors-5">Errors</a></h1>
<p>Returns <code>Err(CannotReallocInPlace)</code> when the allocator is
unable to assert that the memory block referenced by <code>ptr</code>
could fit <code>layout</code>.</p>
<p>Note that one cannot pass <code>CannotReallocInPlace</code> to the <code>handle_alloc_error</code>
function; clients are expected either to be able to recover from
<code>grow_in_place</code> failures without aborting, or to fall back on
another reallocation method before resorting to an abort.</p>
</div><h3 id='method.shrink_in_place' class='method'><span id='shrink_in_place.v' class='invisible'><code>unsafe fn <a href='#method.shrink_in_place' class='fnname'>shrink_in_place</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;u8&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;layout: <a class="struct" href="../../core/alloc/struct.Layout.html" title="struct core::alloc::Layout">Layout</a>, <br>&nbsp;&nbsp;&nbsp;&nbsp;new_size: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.CannotReallocInPlace.html" title="struct core::alloc::CannotReallocInPlace">CannotReallocInPlace</a>&gt;</code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Attempts to shrink the allocation referenced by <code>ptr</code> to fit <code>new_size</code>.</p>
<p>If this returns <code>Ok</code>, then the allocator has asserted that the
memory block referenced by <code>ptr</code> now fits <code>new_size</code>, and
thus can only be used to carry data of that smaller
layout. (The allocator is allowed to take advantage of this,
carving off portions of the block for reuse elsewhere.) The
truncated contents of the block within the smaller layout are
unaltered, and ownership of block has not been transferred.</p>
<p>If this returns <code>Err</code>, then the memory block is considered to
still represent the original (larger) <code>layout</code>. None of the
block has been carved off for reuse elsewhere, ownership of
the memory block has not been transferred, and the contents of
the memory block are unaltered.</p>
<h1 id="safety-7" class="section-header"><a href="#safety-7">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following:</p>
<ul>
<li>
<p><code>ptr</code> must be currently allocated via this allocator,</p>
</li>
<li>
<p><code>layout</code> must <em>fit</em> the <code>ptr</code> (see above); note the
<code>new_size</code> argument need not fit it,</p>
</li>
<li>
<p><code>new_size</code> must not be greater than <code>layout.size()</code>
(and must be greater than zero),</p>
</li>
</ul>
<h1 id="errors-6" class="section-header"><a href="#errors-6">Errors</a></h1>
<p>Returns <code>Err(CannotReallocInPlace)</code> when the allocator is
unable to assert that the memory block referenced by <code>ptr</code>
could fit <code>layout</code>.</p>
<p>Note that one cannot pass <code>CannotReallocInPlace</code> to the <code>handle_alloc_error</code>
function; clients are expected either to be able to recover from
<code>shrink_in_place</code> failures without aborting, or to fall back
on another reallocation method before resorting to an abort.</p>
</div><h3 id='method.alloc_one' class='method'><span id='alloc_one.v' class='invisible'><code>fn <a href='#method.alloc_one' class='fnname'>alloc_one</a>&lt;T&gt;(&amp;mut self) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Allocates a block suitable for holding an instance of <code>T</code>.</p>
<p>Captures a common usage pattern for allocators.</p>
<p>The returned block is suitable for passing to the
<code>alloc</code>/<code>realloc</code> methods of this allocator.</p>
<p>Note to implementors: If this returns <code>Ok(ptr)</code>, then <code>ptr</code>
must be considered &quot;currently allocated&quot; and must be
acceptable input to methods such as <code>realloc</code> or <code>dealloc</code>,
<em>even if</em> <code>T</code> is a zero-sized type. In other words, if your
<code>Alloc</code> implementation overrides this method in a manner
that can return a zero-sized <code>ptr</code>, then all reallocation and
deallocation methods need to be similarly overridden to accept
such values as input.</p>
<h1 id="errors-7" class="section-header"><a href="#errors-7">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>T</code> does not meet allocator's size or alignment constraints.</p>
<p>For zero-sized <code>T</code>, may return either of <code>Ok</code> or <code>Err</code>, but
will <em>not</em> yield undefined behavior.</p>
<p>Clients wishing to abort computation in response to an
allocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.dealloc_one' class='method'><span id='dealloc_one.v' class='invisible'><code>unsafe fn <a href='#method.dealloc_one' class='fnname'>dealloc_one</a>&lt;T&gt;(&amp;mut self, ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;) <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Deallocates a block suitable for holding an instance of <code>T</code>.</p>
<p>The given block must have been produced by this allocator,
and must be suitable for storing a <code>T</code> (in terms of alignment
as well as minimum and maximum size); otherwise yields
undefined behavior.</p>
<p>Captures a common usage pattern for allocators.</p>
<h1 id="safety-8" class="section-header"><a href="#safety-8">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure both:</p>
<ul>
<li>
<p><code>ptr</code> must denote a block of memory currently allocated via this allocator</p>
</li>
<li>
<p>the layout of <code>T</code> must <em>fit</em> that block of memory.</p>
</li>
</ul>
</div><h3 id='method.alloc_array' class='method'><span id='alloc_array.v' class='invisible'><code>fn <a href='#method.alloc_array' class='fnname'>alloc_array</a>&lt;T&gt;(&amp;mut self, n: usize) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Allocates a block suitable for holding <code>n</code> instances of <code>T</code>.</p>
<p>Captures a common usage pattern for allocators.</p>
<p>The returned block is suitable for passing to the
<code>alloc</code>/<code>realloc</code> methods of this allocator.</p>
<p>Note to implementors: If this returns <code>Ok(ptr)</code>, then <code>ptr</code>
must be considered &quot;currently allocated&quot; and must be
acceptable input to methods such as <code>realloc</code> or <code>dealloc</code>,
<em>even if</em> <code>T</code> is a zero-sized type. In other words, if your
<code>Alloc</code> implementation overrides this method in a manner
that can return a zero-sized <code>ptr</code>, then all reallocation and
deallocation methods need to be similarly overridden to accept
such values as input.</p>
<h1 id="errors-8" class="section-header"><a href="#errors-8">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>[T; n]</code> does not meet allocator's size or alignment
constraints.</p>
<p>For zero-sized <code>T</code> or <code>n == 0</code>, may return either of <code>Ok</code> or
<code>Err</code>, but will <em>not</em> yield undefined behavior.</p>
<p>Always returns <code>Err</code> on arithmetic overflow.</p>
<p>Clients wishing to abort computation in response to an
allocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.realloc_array' class='method'><span id='realloc_array.v' class='invisible'><code>unsafe fn <a href='#method.realloc_array' class='fnname'>realloc_array</a>&lt;T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;n_old: usize, <br>&nbsp;&nbsp;&nbsp;&nbsp;n_new: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Reallocates a block previously suitable for holding <code>n_old</code>
instances of <code>T</code>, returning a block suitable for holding
<code>n_new</code> instances of <code>T</code>.</p>
<p>Captures a common usage pattern for allocators.</p>
<p>The returned block is suitable for passing to the
<code>alloc</code>/<code>realloc</code> methods of this allocator.</p>
<h1 id="safety-9" class="section-header"><a href="#safety-9">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure all of the following:</p>
<ul>
<li>
<p><code>ptr</code> must be currently allocated via this allocator,</p>
</li>
<li>
<p>the layout of <code>[T; n_old]</code> must <em>fit</em> that block of memory.</p>
</li>
</ul>
<h1 id="errors-9" class="section-header"><a href="#errors-9">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either memory is exhausted or
<code>[T; n_new]</code> does not meet allocator's size or alignment
constraints.</p>
<p>For zero-sized <code>T</code> or <code>n_new == 0</code>, may return either of <code>Ok</code> or
<code>Err</code>, but will <em>not</em> yield undefined behavior.</p>
<p>Always returns <code>Err</code> on arithmetic overflow.</p>
<p>Clients wishing to abort computation in response to a
reallocation error are encouraged to call the <a href="../../alloc/alloc/fn.handle_alloc_error.html"><code>handle_alloc_error</code></a> function,
rather than directly invoking <code>panic!</code> or similar.</p>
</div><h3 id='method.dealloc_array' class='method'><span id='dealloc_array.v' class='invisible'><code>unsafe fn <a href='#method.dealloc_array' class='fnname'>dealloc_array</a>&lt;T&gt;(<br>&nbsp;&nbsp;&nbsp;&nbsp;&amp;mut self, <br>&nbsp;&nbsp;&nbsp;&nbsp;ptr: <a class="struct" href="../../core/ptr/struct.NonNull.html" title="struct core::ptr::NonNull">NonNull</a>&lt;T&gt;, <br>&nbsp;&nbsp;&nbsp;&nbsp;n: usize<br>) -&gt; <a class="enum" href="../../core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;(), <a class="struct" href="../../core/alloc/struct.AllocErr.html" title="struct core::alloc::AllocErr">AllocErr</a>&gt; <span class="where fmt-newline">where<br>&nbsp;&nbsp;&nbsp;&nbsp;Self: <a class="trait" href="../../core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a>,&nbsp;</span></code></span></h3><div class='stability'><div class='stab unstable'><span class=microscope>🔬</span> This is a nightly-only experimental API.  (<code>allocator_api </code><a href="https://github.com/rust-lang/rust/issues/32838">#32838</a>)</div></div><div class='docblock'><p>Deallocates a block suitable for holding <code>n</code> instances of <code>T</code>.</p>
<p>Captures a common usage pattern for allocators.</p>
<h1 id="safety-10" class="section-header"><a href="#safety-10">Safety</a></h1>
<p>This function is unsafe because undefined behavior can result
if the caller does not ensure both:</p>
<ul>
<li>
<p><code>ptr</code> must denote a block of memory currently allocated via this allocator</p>
</li>
<li>
<p>the layout of <code>[T; n]</code> must <em>fit</em> that block of memory.</p>
</li>
</ul>
<h1 id="errors-10" class="section-header"><a href="#errors-10">Errors</a></h1>
<p>Returning <code>Err</code> indicates that either <code>[T; n]</code> or the given
memory block does not meet allocator's size or alignment
constraints.</p>
<p>Always returns <code>Err</code> on arithmetic overflow.</p>
</div></div>
        <h2 id='implementors' class='small-section-header'>
          Implementors<a href='#implementors' class='anchor'></a>
        </h2>
        <ul class='item-list' id='implementors-list'>
    </ul><script type="text/javascript">window.inlined_types=new Set([]);</script><script type="text/javascript" async
                         src="../../implementors/core/alloc/trait.Alloc.js">
                 </script></section><section id="search" class="content hidden"></section><section class="footer"></section><aside id="help" class="hidden"><div><h1 class="hidden">Help</h1><div class="shortcuts"><h2>Keyboard Shortcuts</h2><dl><dt><kbd>?</kbd></dt><dd>Show this help dialog</dd><dt><kbd>S</kbd></dt><dd>Focus the search field</dd><dt><kbd>↑</kbd></dt><dd>Move up in search results</dd><dt><kbd>↓</kbd></dt><dd>Move down in search results</dd><dt><kbd>↹</kbd></dt><dd>Switch tab</dd><dt><kbd>&#9166;</kbd></dt><dd>Go to active search result</dd><dt><kbd>+</kbd></dt><dd>Expand all sections</dd><dt><kbd>-</kbd></dt><dd>Collapse all sections</dd></dl></div><div class="infos"><h2>Search Tricks</h2><p>Prefix searches with a type followed by a colon (e.g. <code>fn:</code>) to restrict the search to a given type.</p><p>Accepted types are: <code>fn</code>, <code>mod</code>, <code>struct</code>, <code>enum</code>, <code>trait</code>, <code>type</code>, <code>macro</code>, and <code>const</code>.</p><p>Search functions by type signature (e.g. <code>vec -> usize</code> or <code>* -> vec</code>)</p><p>Search multiple things at once by splitting your query with comma (e.g. <code>str,u8</code> or <code>String,struct:Vec,test</code>)</p></div></div></aside><script>window.rootPath = "../../";window.currentCrate = "core";</script><script src="../../aliases.js"></script><script src="../../main.js"></script><script defer src="../../search-index.js"></script></body></html>