<p dir="auto"><code class="notranslate">vec</code> previously had some code that looked like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let vp: *T = ...;
let v = move *vp;"><pre class="notranslate"><code class="notranslate">let vp: *T = ...;
let v = move *vp;
</code></pre></div>
<p dir="auto">This had the effect of memcpying <code class="notranslate">*vp</code> to <code class="notranslate">v</code> and zeroing <code class="notranslate">*vp</code>. <code class="notranslate">move</code> is being removed so this doesn't work. I've replaced that with:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let mut vp: *T = ...;
let mut v: T = rusti::init(); // Create a zeroed value
v &lt;-&gt; *vp;"><pre class="notranslate"><code class="notranslate">let mut vp: *T = ...;
let mut v: T = rusti::init(); // Create a zeroed value
v &lt;-&gt; *vp;
</code></pre></div>
<p dir="auto">This could probably be more efficient by 1) not zeroing the value (in most cases), 2) not doing the swap.</p>
<p dir="auto">Probably this is what we should do:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let mut vp: *T = ...;
let mut v: T = rusti::uninit(); // Create a non-zeroed value
ptr:memcpy(&amp;mut T, vp, 1);"><pre class="notranslate"><code class="notranslate">let mut vp: *T = ...;
let mut v: T = rusti::uninit(); // Create a non-zeroed value
ptr:memcpy(&amp;mut T, vp, 1);
</code></pre></div>
<p dir="auto">And if you need the zeroing you can do a memset.</p>
<p dir="auto">Perhaps we should add an intrinsic like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn zero&lt;T: POD&gt;() -&gt; T"><pre class="notranslate"><code class="notranslate">fn zero&lt;T: POD&gt;() -&gt; T
</code></pre></div>
<p dir="auto">that basically fills <code class="notranslate">T</code> with zeros.  This is perfectly safe for POD types.  Of course, we don't have a POD kind yet, but that's a separate issue I guess.  This is particularly useful in C interop, where you often have functions with out-params that otherwise need to be initialized by hand.</p>
<p dir="auto">We could also add an intrinsic like</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fn undefined&lt;T: POD&gt;() -&gt; T"><pre class="notranslate"><code class="notranslate">fn undefined&lt;T: POD&gt;() -&gt; T
</code></pre></div>
<p dir="auto">which would just leave the data uninitialized.  This would be more efficient but less safe in some sense.  Though restricting it to POD at least preserves memory safety, more-or-less.</p>
<p dir="auto">The idea is you'd write something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="struct FooResult { /*something POD*/ }

extern mod c_library { fn foo(p: &amp;mut FooResult) -&gt; bool; }

fn foo() -&gt; FooResult {
    let result = defined();
    if !c_library::foo(&amp;mut result) { fail; }
    return result;
}"><pre class="notranslate"><code class="notranslate">struct FooResult { /*something POD*/ }

extern mod c_library { fn foo(p: &amp;mut FooResult) -&gt; bool; }

fn foo() -&gt; FooResult {
    let result = defined();
    if !c_library::foo(&amp;mut result) { fail; }
    return result;
}
</code></pre></div>