<p dir="auto">These duplicate the functionality of e.g. <code class="notranslate">uint::range</code></p>
<p dir="auto">The signature of <code class="notranslate">from_raw_buf</code> is:</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="fn from_raw_buf&lt;T&gt;(p: &amp;'a *const T, len: uint) -&gt; &amp;'a [T]"><pre class="notranslate"><span class="pl-k">fn</span> <span class="pl-en">from_raw_buf</span><span class="pl-kos">&lt;</span><span class="pl-smi">T</span><span class="pl-kos">&gt;</span><span class="pl-kos">(</span><span class="pl-s1">p</span><span class="pl-kos">:</span> <span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">a</span> <span class="pl-c1">*</span><span class="pl-k">const</span> <span class="pl-smi">T</span><span class="pl-kos">,</span> <span class="pl-s1">len</span><span class="pl-kos">:</span> <span class="pl-smi">uint</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">a</span> <span class="pl-kos">[</span><span class="pl-smi">T</span><span class="pl-kos">]</span><span class="pl-kos"></span></pre></div>
<p dir="auto">The fact that the lifetime of the returned slice is the same as the lifetime of the pointer is a very bad idea. And now that <code class="notranslate">CVec</code> is gone, this is the only way to build a slice from a raw pointer.</p>
<p dir="auto">I can see many potential problems, but the ones that I've encountered while removing CVec is that you can't cast your pointers, not even from mut to const: (<a href="http://is.gd/eW1KmQ" rel="nofollow">http://is.gd/eW1KmQ</a>)</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct Foo { data: *mut i8, len: uint }
impl Foo {
    fn as_slice(&amp;self) -&gt; &amp;[i8] {
        unsafe {
            // value &quot;self.data as *const i8&quot; does not live long enough
            std::slice::from_raw_buf(&amp;(self.data as *const i8), self.len)
        }
    }
}"><pre class="notranslate"><span class="pl-k">struct</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span> <span class="pl-c1">data</span><span class="pl-kos">:</span> <span class="pl-c1">*</span><span class="pl-k">mut</span> <span class="pl-smi">i8</span><span class="pl-kos">,</span> <span class="pl-c1">len</span><span class="pl-kos">:</span> <span class="pl-smi">uint</span> <span class="pl-kos">}</span>
<span class="pl-k">impl</span> <span class="pl-smi">Foo</span> <span class="pl-kos">{</span>
    <span class="pl-k">fn</span> <span class="pl-en">as_slice</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-c1">&amp;</span><span class="pl-kos">[</span><span class="pl-smi">i8</span><span class="pl-kos">]</span> <span class="pl-kos">{</span>
        <span class="pl-k">unsafe</span> <span class="pl-kos">{</span>
            <span class="pl-c">// value "self.data as *const i8" does not live long enough</span>
            std<span class="pl-kos">::</span>slice<span class="pl-kos">::</span><span class="pl-en">from_raw_buf</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-kos">(</span><span class="pl-smi">self</span><span class="pl-kos">.</span><span class="pl-c1">data</span> <span class="pl-k">as</span> <span class="pl-c1">*</span><span class="pl-k">const</span> <span class="pl-smi">i8</span><span class="pl-kos">)</span><span class="pl-kos">,</span> <span class="pl-smi">self</span><span class="pl-kos">.</span><span class="pl-c1">len</span><span class="pl-kos">)</span>
        <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">And that you can't use raw pointers in iterators anymore: (<a href="http://is.gd/UsePsX" rel="nofollow">http://is.gd/UsePsX</a>)</p>
<div class="highlight highlight-source-rust notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct Iter&lt;'a&gt; { data: *const u8, marker: ContravariantLifetime&lt;'a&gt; }
impl&lt;'a&gt; Iterator for Iter&lt;'a&gt; {
    type Item = &amp;'a [u8];
    fn next(&amp;mut self) -&gt; Option&lt;&amp;'a [u8]&gt; {
        Some(unsafe {
            // cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
            std::slice::from_raw_buf(&amp;self.data, 1)
        })
    }
}"><pre class="notranslate"><span class="pl-k">struct</span> <span class="pl-smi">Iter</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span> <span class="pl-c1">data</span><span class="pl-kos">:</span> <span class="pl-c1">*</span><span class="pl-k">const</span> <span class="pl-smi">u8</span><span class="pl-kos">,</span> <span class="pl-c1">marker</span><span class="pl-kos">:</span> <span class="pl-smi">ContravariantLifetime</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">}</span>
<span class="pl-k">impl</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-smi">Iterator</span> <span class="pl-k">for</span> <span class="pl-smi">Iter</span><span class="pl-kos">&lt;</span><span class="pl-c1">'</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
    <span class="pl-k">type</span> <span class="pl-smi">Item</span> = <span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">a</span> <span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">;</span>
    <span class="pl-k">fn</span> <span class="pl-en">next</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-k">mut</span> <span class="pl-smi">self</span><span class="pl-kos">)</span> -&gt; <span class="pl-smi">Option</span><span class="pl-kos">&lt;</span><span class="pl-c1">&amp;</span><span class="pl-c1">'</span><span class="pl-ent">a</span> <span class="pl-kos">[</span><span class="pl-smi">u8</span><span class="pl-kos">]</span><span class="pl-kos">&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-v">Some</span><span class="pl-kos">(</span><span class="pl-k">unsafe</span> <span class="pl-kos">{</span>
            <span class="pl-c">// cannot infer an appropriate lifetime for borrow expression due to conflicting requirements</span>
            std<span class="pl-kos">::</span>slice<span class="pl-kos">::</span><span class="pl-en">from_raw_buf</span><span class="pl-kos">(</span><span class="pl-c1">&amp;</span><span class="pl-smi">self</span><span class="pl-kos">.</span><span class="pl-c1">data</span><span class="pl-kos">,</span> <span class="pl-c1">1</span><span class="pl-kos">)</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span>
    <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">If I'm manipulating raw pointers which are unsafe by nature, please let me be unsafe!</p>
<p dir="auto">The first example can be bypassed by using <code class="notranslate">from_raw_mut_buf</code> and casting the returned <code class="notranslate">&amp;mut [i8]</code> to a <code class="notranslate">&amp;[i8]</code>, which means that the unsafe API is more restrictive than the safe API!</p>