<p dir="auto">This issue is intended to represent the outstanding issues for stabilizing libcore and allowing its usage on stable Rust. There are a number of features currently associated with libcore:</p>
<ul dir="auto">
<li><code class="notranslate">core</code></li>
<li><code class="notranslate">core_char_ext</code></li>
<li><code class="notranslate">core_prelude</code></li>
<li><code class="notranslate">core_slice_ext</code></li>
<li><code class="notranslate">core_str_ext</code></li>
</ul>
<p dir="auto">(note that <code class="notranslate">core_float</code> will be handled in a separate issue)</p>
<p dir="auto">The design of libcore largely mirrors that of the standard library (good) but there are a few deviations:</p>
<ul dir="auto">
<li><code class="notranslate">core::atomic</code> differs from <code class="notranslate">std::sync::atomic</code></li>
<li>Modules like <code class="notranslate">nonzero</code>, <code class="notranslate">panicking</code>, and <code class="notranslate">array</code> are public</li>
</ul>
<p dir="auto">Overall there are a number of tasks that probably need to be done before stabilizing these items:</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> A full audit should be done to ensure that the structure of libcore is the same as the structure of libstd</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> The name <code class="notranslate">core</code> needs to be agreed upon as the stable name for the library</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> The set of extension traits for primitives needs to be decided upon. This strategy of trait-in-core and inherent-above-core should be agreed upon as the best path forward.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> The set of items in the prelude should be audited to ensure it's a subset of the standard library's</li>
</ul>
<p dir="auto">I'm not sure of the correct bug title here, it's based on my limited understanding of the problem :)</p>
<p dir="auto">I'm trying to write a DB wrapper with a cache. Here's a code sample with two variants of read() function, the DB is using a hash map as well for exposition.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="use std::hashmap::HashMap;

#[deriving(Clone)]
struct Data {
    data: ~[u8]
}

struct DB {
    cache: HashMap&lt;int, Data&gt;,
    db: HashMap&lt;int, Data&gt;
}

impl DB {
    pub fn read1&lt;'a&gt;(&amp;'a mut self, key: int) -&gt; Option&lt;&amp;'a Data&gt; {
        match self.cache.find(&amp;key) {
            Some(data) =&gt; return Some(data),
            None =&gt; ()
        };

        match self.db.find(&amp;key) {
            Some(data) =&gt; {
                let result: &amp;Data = self.cache.find_or_insert(key, data.clone());

                Some(result)
            },
            None =&gt; None
        }
    }

    pub fn read2&lt;'a&gt;(&amp;'a mut self, key: int) -&gt; Option&lt;&amp;'a Data&gt; {
        match self.cache.find(&amp;key) {
            Some(data) =&gt; return Some(data),
            None =&gt; {
                match self.db.find(&amp;key) {
                    Some(data) =&gt; {
                        let result: &amp;Data = self.cache.find_or_insert(key, data.clone());

                        Some(result)
                    },
                    None =&gt; None
                }
            }
        }
    }
}

fn main() {
}"><pre class="notranslate"><code class="notranslate">use std::hashmap::HashMap;

#[deriving(Clone)]
struct Data {
    data: ~[u8]
}

struct DB {
    cache: HashMap&lt;int, Data&gt;,
    db: HashMap&lt;int, Data&gt;
}

impl DB {
    pub fn read1&lt;'a&gt;(&amp;'a mut self, key: int) -&gt; Option&lt;&amp;'a Data&gt; {
        match self.cache.find(&amp;key) {
            Some(data) =&gt; return Some(data),
            None =&gt; ()
        };

        match self.db.find(&amp;key) {
            Some(data) =&gt; {
                let result: &amp;Data = self.cache.find_or_insert(key, data.clone());

                Some(result)
            },
            None =&gt; None
        }
    }

    pub fn read2&lt;'a&gt;(&amp;'a mut self, key: int) -&gt; Option&lt;&amp;'a Data&gt; {
        match self.cache.find(&amp;key) {
            Some(data) =&gt; return Some(data),
            None =&gt; {
                match self.db.find(&amp;key) {
                    Some(data) =&gt; {
                        let result: &amp;Data = self.cache.find_or_insert(key, data.clone());

                        Some(result)
                    },
                    None =&gt; None
                }
            }
        }
    }
}

fn main() {
}
</code></pre></div>
<p dir="auto">Both read1() and read2() fail to compile with the following error:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="db.rs:22:36: 22:46 error: cannot borrow `(*self).cache` as mutable because it is also borrowed as immutable
db.rs:22                 let result: &amp;Data = self.cache.find_or_insert(key, data.clone());
                                             ^~~~~~~~~~
db.rs:15:14: 15:24 note: second borrow of `(*self).cache` occurs here
db.rs:15         match self.cache.find(&amp;key) {
                       ^~~~~~~~~~"><pre class="notranslate"><code class="notranslate">db.rs:22:36: 22:46 error: cannot borrow `(*self).cache` as mutable because it is also borrowed as immutable
db.rs:22                 let result: &amp;Data = self.cache.find_or_insert(key, data.clone());
                                             ^~~~~~~~~~
db.rs:15:14: 15:24 note: second borrow of `(*self).cache` occurs here
db.rs:15         match self.cache.find(&amp;key) {
                       ^~~~~~~~~~
</code></pre></div>
<p dir="auto">Possibly a duplicate of <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="14199471" data-permission-text="Title is private" data-url="https://github.com/rust-lang/rust/issues/6393" data-hovercard-type="issue" data-hovercard-url="/rust-lang/rust/issues/6393/hovercard" href="https://github.com/rust-lang/rust/issues/6393">#6393</a> (although read1 looked like it could solve the problem but did not).</p>