<!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 `Rc` struct in crate `std`."> <meta name="keywords" content="rust, rustlang, rust-lang, Rc"> <title>std::rc::Rc - Rust</title> <link rel="stylesheet" type="text/css" href="../../normalize.css"> <link rel="stylesheet" type="text/css" href="../../rustdoc.css"> <link rel="stylesheet" type="text/css" href="../../main.css"> <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico"> </head> <body class="rustdoc struct"> <!--[if lte IE 8]> <div class="warning"> This old browser is unsupported and will most likely display funky things. </div> <![endif]--> <nav class="sidebar"> <a href='../../std/index.html'><img src='https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a> <p class='location'>Struct Rc</p><div class="block items"><ul><li><a href="#methods">Methods</a></li><li><a href="#implementations">Trait Implementations</a></li></ul></div><p class='location'><a href='../index.html'>std</a>::<wbr><a href='index.html'>rc</a></p><script>window.sidebarCurrent = {name: 'Rc', ty: 'struct', relpath: ''};</script><script defer src="sidebar-items.js"></script> </nav> <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"> </div> </form> </nav> <section id='main' class="content"> <h1 class='fqn'><span class='in-band'>Struct <a href='../index.html'>std</a>::<wbr><a href='index.html'>rc</a>::<wbr><a class="struct" href=''>Rc</a></span><span class='out-of-band'><span class='since' title='Stable since Rust version 1.0.0'>1.0.0</span><span id='render-detail'> <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs"> [<span class='inner'>−</span>] </a> </span><a class='srclink' href='../../src/alloc/rc.rs.html#280-282' title='goto source code'>[src]</a></span></h1> <pre class='rust struct'>pub struct Rc<T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span> { /* fields omitted */ }</pre><div class='docblock'><p>A single-threaded reference-counting pointer.</p> <p>See the <a href="./index.html">module-level documentation</a> for more details.</p> <p>The inherent methods of <code>Rc</code> are all associated functions, which means that you have to call them as e.g. <a href="#method.get_mut"><code>Rc::get_mut(&value)</code></a> instead of <code>value.get_mut()</code>. This avoids conflicts with methods of the inner type <code>T</code>.</p> </div><h2 id='methods'>Methods</h2><h3 class='impl'><span class='in-band'><code>impl<T> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#292-422' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.new' class="method"><span id='new.v' class='invisible'><code>fn <a href='#method.new' class='fnname'>new</a>(value: T) -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span></h4> <div class='docblock'><p>Constructs a new <code>Rc<T></code>.</p> <h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%7D">Run</a></pre> </div><h4 id='method.try_unwrap' class="method"><span id='try_unwrap.v' class='invisible'><code>fn <a href='#method.try_unwrap' class='fnname'>try_unwrap</a>(this: <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><T, <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4> <div class='docblock'><p>Returns the contained value, if the <code>Rc</code> has exactly one strong reference.</p> <p>Otherwise, an <a href="../../std/result/enum.Result.html"><code>Err</code></a> is returned with the same <code>Rc</code> that was passed in.</p> <p>This will succeed even if there are outstanding weak references.</p> <h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">3</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Rc</span>::<span class="ident">try_unwrap</span>(<span class="ident">x</span>), <span class="prelude-val">Ok</span>(<span class="number">3</span>)); <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">4</span>); <span class="kw">let</span> <span class="ident">_y</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">x</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">try_unwrap</span>(<span class="ident">x</span>).<span class="ident">unwrap_err</span>(), <span class="number">4</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20x%20%3D%20Rc%3A%3Anew(3)%3B%0Aassert_eq!(Rc%3A%3Atry_unwrap(x)%2C%20Ok(3))%3B%0A%0Alet%20x%20%3D%20Rc%3A%3Anew(4)%3B%0Alet%20_y%20%3D%20Rc%3A%3Aclone(%26x)%3B%0Aassert_eq!(*Rc%3A%3Atry_unwrap(x).unwrap_err()%2C%204)%3B%0A%7D">Run</a></pre> </div><h4 id='method.into_raw' class="method"><span id='into_raw.v' class='invisible'><code>fn <a href='#method.into_raw' class='fnname'>into_raw</a>(this: <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.pointer.html">*const T</a></code><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div></span></h4> <div class='docblock'><p>Consumes the <code>Rc</code>, returning the wrapped pointer.</p> <p>To avoid a memory leak the pointer must be converted back to an <code>Rc</code> using <a href="struct.Rc.html#method.from_raw"><code>Rc::from_raw</code></a>.</p> <h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">10</span>); <span class="kw">let</span> <span class="ident">x_ptr</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">into_raw</span>(<span class="ident">x</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw">unsafe</span> { <span class="kw-2">*</span><span class="ident">x_ptr</span> }, <span class="number">10</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20x%20%3D%20Rc%3A%3Anew(10)%3B%0Alet%20x_ptr%20%3D%20Rc%3A%3Ainto_raw(x)%3B%0Aassert_eq!(unsafe%20%7B%20*x_ptr%20%7D%2C%2010)%3B%0A%7D">Run</a></pre> </div><h4 id='method.from_raw' class="method"><span id='from_raw.v' class='invisible'><code>unsafe fn <a href='#method.from_raw' class='fnname'>from_raw</a>(ptr: <a class="primitive" href="../primitive.pointer.html">*const T</a>) -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div></span></h4> <div class='docblock'><p>Constructs an <code>Rc</code> from a raw pointer.</p> <p>The raw pointer must have been previously returned by a call to a <a href="struct.Rc.html#method.into_raw"><code>Rc::into_raw</code></a>.</p> <p>This function is unsafe because improper use may lead to memory problems. For example, a double-free may occur if the function is called twice on the same raw pointer.</p> <h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">10</span>); <span class="kw">let</span> <span class="ident">x_ptr</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">into_raw</span>(<span class="ident">x</span>); <span class="kw">unsafe</span> { <span class="comment">// Convert back to an `Rc` to prevent leak.</span> <span class="kw">let</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">from_raw</span>(<span class="ident">x_ptr</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">x</span>, <span class="number">10</span>); <span class="comment">// Further calls to `Rc::from_raw(x_ptr)` would be memory unsafe.</span> } <span class="comment">// The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20x%20%3D%20Rc%3A%3Anew(10)%3B%0Alet%20x_ptr%20%3D%20Rc%3A%3Ainto_raw(x)%3B%0A%0Aunsafe%20%7B%0A%20%20%20%20%2F%2F%20Convert%20back%20to%20an%20%60Rc%60%20to%20prevent%20leak.%0A%20%20%20%20let%20x%20%3D%20Rc%3A%3Afrom_raw(x_ptr)%3B%0A%20%20%20%20assert_eq!(*x%2C%2010)%3B%0A%0A%20%20%20%20%2F%2F%20Further%20calls%20to%20%60Rc%3A%3Afrom_raw(x_ptr)%60%20would%20be%20memory%20unsafe.%0A%7D%0A%0A%2F%2F%20The%20memory%20was%20freed%20when%20%60x%60%20went%20out%20of%20scope%20above%2C%20so%20%60x_ptr%60%20is%20now%20dangling!%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#481-606' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.downgrade' class="method"><span id='downgrade.v' class='invisible'><code>fn <a href='#method.downgrade' class='fnname'>downgrade</a>(this: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="struct" href="../../std/rc/struct.Weak.html" title="struct std::rc::Weak">Weak</a><T></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4> <div class='docblock'><p>Creates a new <a href="struct.Weak.html"><code>Weak</code></a> pointer to this value.</p> <h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="kw">let</span> <span class="ident">weak_five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">downgrade</span>(<span class="kw-2">&</span><span class="ident">five</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Alet%20weak_five%20%3D%20Rc%3A%3Adowngrade(%26five)%3B%0A%7D">Run</a></pre> </div><h4 id='method.weak_count' class="method"><span id='weak_count.v' class='invisible'><code>fn <a href='#method.weak_count' class='fnname'>weak_count</a>(this: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.usize.html">usize</a></code><div class='since' title='Stable since Rust version 1.15.0'>1.15.0</div></span></h4> <div class='docblock'><p>Gets the number of <a href="struct.Weak.html"><code>Weak</code></a> pointers to this value.</p> <h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="kw">let</span> <span class="ident">_weak_five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">downgrade</span>(<span class="kw-2">&</span><span class="ident">five</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">1</span>, <span class="ident">Rc</span>::<span class="ident">weak_count</span>(<span class="kw-2">&</span><span class="ident">five</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0Alet%20_weak_five%20%3D%20Rc%3A%3Adowngrade(%26five)%3B%0A%0Aassert_eq!(1%2C%20Rc%3A%3Aweak_count(%26five))%3B%0A%7D">Run</a></pre> </div><h4 id='method.strong_count' class="method"><span id='strong_count.v' class='invisible'><code>fn <a href='#method.strong_count' class='fnname'>strong_count</a>(this: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.usize.html">usize</a></code><div class='since' title='Stable since Rust version 1.15.0'>1.15.0</div></span></h4> <div class='docblock'><p>Gets the number of strong (<code>Rc</code>) pointers to this value.</p> <h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="kw">let</span> <span class="ident">_also_five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">five</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">2</span>, <span class="ident">Rc</span>::<span class="ident">strong_count</span>(<span class="kw-2">&</span><span class="ident">five</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0Alet%20_also_five%20%3D%20Rc%3A%3Aclone(%26five)%3B%0A%0Aassert_eq!(2%2C%20Rc%3A%3Astrong_count(%26five))%3B%0A%7D">Run</a></pre> </div><h4 id='method.get_mut' class="method"><span id='get_mut.v' class='invisible'><code>fn <a href='#method.get_mut' class='fnname'>get_mut</a>(this: &mut <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a><&mut T></code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4> <div class='docblock'><p>Returns a mutable reference to the inner value, if there are no other <code>Rc</code> or <a href="struct.Weak.html"><code>Weak</code></a> pointers to the same value.</p> <p>Returns <a href="../../std/option/enum.Option.html#variant.None"><code>None</code></a> otherwise, because it is not safe to mutate a shared value.</p> <p>See also <a href="struct.Rc.html#method.make_mut"><code>make_mut</code></a>, which will <a href="../../std/clone/trait.Clone.html#tymethod.clone"><code>clone</code></a> the inner value when it's shared.</p> <h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">x</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">3</span>); <span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">get_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">x</span>).<span class="ident">unwrap</span>() <span class="op">=</span> <span class="number">4</span>; <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">x</span>, <span class="number">4</span>); <span class="kw">let</span> <span class="ident">_y</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">x</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">Rc</span>::<span class="ident">get_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">x</span>).<span class="ident">is_none</span>());<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20mut%20x%20%3D%20Rc%3A%3Anew(3)%3B%0A*Rc%3A%3Aget_mut(%26mut%20x).unwrap()%20%3D%204%3B%0Aassert_eq!(*x%2C%204)%3B%0A%0Alet%20_y%20%3D%20Rc%3A%3Aclone(%26x)%3B%0Aassert!(Rc%3A%3Aget_mut(%26mut%20x).is_none())%3B%0A%7D">Run</a></pre> </div><h4 id='method.ptr_eq' class="method"><span id='ptr_eq.v' class='invisible'><code>fn <a href='#method.ptr_eq' class='fnname'>ptr_eq</a>(this: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code><div class='since' title='Stable since Rust version 1.17.0'>1.17.0</div></span></h4> <div class='docblock'><p>Returns true if the two <code>Rc</code>s point to the same value (not just values that compare as equal).</p> <h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="kw">let</span> <span class="ident">same_five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">five</span>); <span class="kw">let</span> <span class="ident">other_five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">Rc</span>::<span class="ident">ptr_eq</span>(<span class="kw-2">&</span><span class="ident">five</span>, <span class="kw-2">&</span><span class="ident">same_five</span>)); <span class="macro">assert</span><span class="macro">!</span>(<span class="op">!</span><span class="ident">Rc</span>::<span class="ident">ptr_eq</span>(<span class="kw-2">&</span><span class="ident">five</span>, <span class="kw-2">&</span><span class="ident">other_five</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0Alet%20same_five%20%3D%20Rc%3A%3Aclone(%26five)%3B%0Alet%20other_five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(Rc%3A%3Aptr_eq(%26five%2C%20%26same_five))%3B%0Aassert!(!Rc%3A%3Aptr_eq(%26five%2C%20%26other_five))%3B%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#608-665' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.make_mut' class="method"><span id='make_mut.v' class='invisible'><code>fn <a href='#method.make_mut' class='fnname'>make_mut</a>(this: &mut <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> &mut T</code><div class='since' title='Stable since Rust version 1.4.0'>1.4.0</div></span></h4> <div class='docblock'><p>Makes a mutable reference into the given <code>Rc</code>.</p> <p>If there are other <code>Rc</code> or <a href="struct.Weak.html"><code>Weak</code></a> pointers to the same value, then <code>make_mut</code> will invoke <a href="../../std/clone/trait.Clone.html#tymethod.clone"><code>clone</code></a> on the inner value to ensure unique ownership. This is also referred to as clone-on-write.</p> <p>See also <a href="struct.Rc.html#method.get_mut"><code>get_mut</code></a>, which will fail rather than cloning.</p> <h1 id='examples-9' class='section-header'><a href='#examples-9'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">data</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">make_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">data</span>) <span class="op">+=</span> <span class="number">1</span>; <span class="comment">// Won't clone anything</span> <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">other_data</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">data</span>); <span class="comment">// Won't clone inner data</span> <span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">make_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">data</span>) <span class="op">+=</span> <span class="number">1</span>; <span class="comment">// Clones inner data</span> <span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">make_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">data</span>) <span class="op">+=</span> <span class="number">1</span>; <span class="comment">// Won't clone anything</span> <span class="kw-2">*</span><span class="ident">Rc</span>::<span class="ident">make_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">other_data</span>) <span class="op">*=</span> <span class="number">2</span>; <span class="comment">// Won't clone anything</span> <span class="comment">// Now `data` and `other_data` point to different values.</span> <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">data</span>, <span class="number">8</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">other_data</span>, <span class="number">12</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20mut%20data%20%3D%20Rc%3A%3Anew(5)%3B%0A%0A*Rc%3A%3Amake_mut(%26mut%20data)%20%2B%3D%201%3B%20%20%20%20%20%20%20%20%2F%2F%20Won't%20clone%20anything%0Alet%20mut%20other_data%20%3D%20Rc%3A%3Aclone(%26data)%3B%20%20%20%20%2F%2F%20Won't%20clone%20inner%20data%0A*Rc%3A%3Amake_mut(%26mut%20data)%20%2B%3D%201%3B%20%20%20%20%20%20%20%20%2F%2F%20Clones%20inner%20data%0A*Rc%3A%3Amake_mut(%26mut%20data)%20%2B%3D%201%3B%20%20%20%20%20%20%20%20%2F%2F%20Won't%20clone%20anything%0A*Rc%3A%3Amake_mut(%26mut%20other_data)%20*%3D%202%3B%20%20%2F%2F%20Won't%20clone%20anything%0A%0A%2F%2F%20Now%20%60data%60%20and%20%60other_data%60%20point%20to%20different%20values.%0Aassert_eq!(*data%2C%208)%3B%0Aassert_eq!(*other_data%2C%2012)%3B%0A%7D">Run</a></pre> </div></div><h2 id='implementations'>Trait Implementations</h2><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/hash/trait.Hash.html" title="trait std::hash::Hash">Hash</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#927-931' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.hash' class="method"><span id='hash.v' class='invisible'><code>fn <a href='../../std/hash/trait.Hash.html#tymethod.hash' class='fnname'>hash</a><H>(&self, state: &mut H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>, </span></code></span></h4> <div class='docblock'><p>Feeds this value into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#tymethod.hash">Read more</a></p> </div><h4 id='method.hash_slice' class="method"><span id='hash_slice.v' class='invisible'><code>fn <a href='../../std/hash/trait.Hash.html#method.hash_slice' class='fnname'>hash_slice</a><H>(data: <a class="primitive" href="../primitive.slice.html">&[Self]</a>, state: &mut H) <span class="where fmt-newline">where<br> H: <a class="trait" href="../../std/hash/trait.Hasher.html" title="trait std::hash::Hasher">Hasher</a>, </span></code><div class='since' title='Stable since Rust version 1.3.0'>1.3.0</div></span></h4> <div class='docblock'><p>Feeds a slice of this type into the given [<code>Hasher</code>]. <a href="../../std/hash/trait.Hash.html#method.hash_slice">Read more</a></p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/borrow/trait.Borrow.html" title="trait std::borrow::Borrow">Borrow</a><T> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#1470-1474' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.borrow' class="method"><span id='borrow.v' class='invisible'><code>fn <a href='../../std/borrow/trait.Borrow.html#tymethod.borrow' class='fnname'>borrow</a>(&self) -> &T</code></span></h4> <div class='docblock'><p>Immutably borrows from an owned value. <a href="../../std/borrow/trait.Borrow.html#tymethod.borrow">Read more</a></p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a><<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/cmp/trait.PartialEq.html" title="trait std::cmp::PartialEq">PartialEq</a><T> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#769-805' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.eq' class="method"><span id='eq.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialEq.html#tymethod.eq' class='fnname'>eq</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>Equality for two <code>Rc</code>s.</p> <p>Two <code>Rc</code>s are equal if their inner values are equal.</p> <h1 id='examples-10' class='section-header'><a href='#examples-10'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op">==</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20%3D%3D%20Rc%3A%3Anew(5))%3B%0A%7D">Run</a></pre> </div><h4 id='method.ne' class="method"><span id='ne.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialEq.html#method.ne' class='fnname'>ne</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>Inequality for two <code>Rc</code>s.</p> <p>Two <code>Rc</code>s are unequal if their inner values are unequal.</p> <h1 id='examples-11' class='section-header'><a href='#examples-11'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op">!=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">6</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20!%3D%20Rc%3A%3Anew(6))%3B%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/ops/trait.Drop.html" title="trait std::ops::Drop">Drop</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#678-725' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.drop' class="method"><span id='drop.v' class='invisible'><code>fn <a href='../../std/ops/trait.Drop.html#tymethod.drop' class='fnname'>drop</a>(&mut self)</code></span></h4> <div class='docblock'><p>Drops the <code>Rc</code>.</p> <p>This will decrement the strong reference count. If the strong reference count reaches zero then the only other references (if any) are <a href="struct.Weak.html"><code>Weak</code></a>, so we <code>drop</code> the inner value.</p> <h1 id='examples-12' class='section-header'><a href='#examples-12'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">struct</span> <span class="ident">Foo</span>; <span class="kw">impl</span> <span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">Foo</span> { <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) { <span class="macro">println</span><span class="macro">!</span>(<span class="string">"dropped!"</span>); } } <span class="kw">let</span> <span class="ident">foo</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="ident">Foo</span>); <span class="kw">let</span> <span class="ident">foo2</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">foo</span>); <span class="ident">drop</span>(<span class="ident">foo</span>); <span class="comment">// Doesn't print anything</span> <span class="ident">drop</span>(<span class="ident">foo2</span>); <span class="comment">// Prints "dropped!"</span><a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Astruct%20Foo%3B%0A%0Aimpl%20Drop%20for%20Foo%20%7B%0A%20%20%20%20fn%20drop(%26mut%20self)%20%7B%0A%20%20%20%20%20%20%20%20println!(%22dropped!%22)%3B%0A%20%20%20%20%7D%0A%7D%0A%0Alet%20foo%20%20%3D%20Rc%3A%3Anew(Foo)%3B%0Alet%20foo2%20%3D%20Rc%3A%3Aclone(%26foo)%3B%0A%0Adrop(foo)%3B%20%20%20%20%2F%2F%20Doesn't%20print%20anything%0Adrop(foo2)%3B%20%20%20%2F%2F%20Prints%20%22dropped!%22%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/fmt/trait.Pointer.html" title="trait std::fmt::Pointer">Pointer</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#948-952' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.fmt' class="method"><span id='fmt.v' class='invisible'><code>fn <a href='../../std/fmt/trait.Pointer.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.tuple.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span></h4> <div class='docblock'><p>Formats the value using the given formatter.</p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/ops/trait.Deref.html" title="trait std::ops::Deref">Deref</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#668-675' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='associatedtype.Target' class="type"><span id='Target.t' class='invisible'><code>type <a href='../../std/ops/trait.Deref.html#associatedtype.Target' class="type">Target</a> = T</code></span></h4> <div class='docblock'><p>The resulting type after dereferencing</p> </div><h4 id='method.deref' class="method"><span id='deref.v' class='invisible'><code>fn <a href='../../std/ops/trait.Deref.html#tymethod.deref' class='fnname'>deref</a>(&self) -> &T</code></span></h4> <div class='docblock'><p>The method called to dereference a value</p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/clone/trait.Clone.html" title="trait std::clone::Clone">Clone</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#728-748' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.clone' class="method"><span id='clone.v' class='invisible'><code>fn <a href='../../std/clone/trait.Clone.html#tymethod.clone' class='fnname'>clone</a>(&self) -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span></h4> <div class='docblock'><p>Makes a clone of the <code>Rc</code> pointer.</p> <p>This creates another pointer to the same inner value, increasing the strong reference count.</p> <h1 id='examples-13' class='section-header'><a href='#examples-13'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="ident">Rc</span>::<span class="ident">clone</span>(<span class="kw-2">&</span><span class="ident">five</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0ARc%3A%3Aclone(%26five)%3B%0A%7D">Run</a></pre> </div><h4 id='method.clone_from' class="method"><span id='clone_from.v' class='invisible'><code>fn <a href='../../std/clone/trait.Clone.html#method.clone_from' class='fnname'>clone_from</a>(&mut self, source: &Self)</code></span></h4> <div class='docblock'><p>Performs copy-assignment from <code>source</code>. <a href="../../std/clone/trait.Clone.html#method.clone_from">Read more</a></p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/convert/trait.AsRef.html" title="trait std::convert::AsRef">AsRef</a><T> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.5.0'>1.5.0</div><a class='srclink' href='../../src/alloc/rc.rs.html#1477-1481' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.as_ref' class="method"><span id='as_ref.v' class='invisible'><code>fn <a href='../../std/convert/trait.AsRef.html#tymethod.as_ref' class='fnname'>as_ref</a>(&self) -> &T</code></span></h4> <div class='docblock'><p>Performs the conversion.</p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> !<a class="trait" href="../../std/marker/trait.Send.html" title="trait std::marker::Send">Send</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#285' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/fmt/trait.Debug.html" title="trait std::fmt::Debug">Debug</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#941-945' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.fmt-1' class="method"><span id='fmt.v-1' class='invisible'><code>fn <a href='../../std/fmt/trait.Debug.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.tuple.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span></h4> <div class='docblock'><p>Formats the value using the given formatter.</p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/default/trait.Default.html" title="trait std::default::Default">Default</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#751-766' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.default' class="method"><span id='default.v' class='invisible'><code>fn <a href='../../std/default/trait.Default.html#tymethod.default' class='fnname'>default</a>() -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span></h4> <div class='docblock'><p>Creates a new <code>Rc<T></code>, with the <code>Default</code> value for <code>T</code>.</p> <h1 id='examples-14' class='section-header'><a href='#examples-14'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">x</span>: <span class="ident">Rc</span><span class="op"><</span><span class="ident">i32</span><span class="op">></span> <span class="op">=</span> <span class="ident">Default</span>::<span class="ident">default</span>(); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="kw-2">*</span><span class="ident">x</span>, <span class="number">0</span>);<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20x%3A%20Rc%3Ci32%3E%20%3D%20Default%3A%3Adefault()%3B%0Aassert_eq!(*x%2C%200)%3B%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/cmp/trait.Ord.html" title="trait std::cmp::Ord">Ord</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/cmp/trait.Ord.html" title="trait std::cmp::Ord">Ord</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#905-924' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.cmp' class="method"><span id='cmp.v' class='invisible'><code>fn <a href='../../std/cmp/trait.Ord.html#tymethod.cmp' class='fnname'>cmp</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a></code></span></h4> <div class='docblock'><p>Comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code>cmp()</code> on their inner values.</p> <h1 id='examples-15' class='section-header'><a href='#examples-15'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">cmp</span>::<span class="ident">Ordering</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">Ordering</span>::<span class="ident">Less</span>, <span class="ident">five</span>.<span class="ident">cmp</span>(<span class="kw-2">&</span><span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">6</span>)));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0Ause%20std%3A%3Acmp%3A%3AOrdering%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert_eq!(Ordering%3A%3ALess%2C%20five.cmp(%26Rc%3A%3Anew(6)))%3B%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T, U> <a class="trait" href="../../std/ops/trait.CoerceUnsized.html" title="trait std::ops::CoerceUnsized">CoerceUnsized</a><<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><U>> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/marker/trait.Unsize.html" title="trait std::marker::Unsize">Unsize</a><U> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>,<br> U: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#290' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/cmp/trait.PartialOrd.html" title="trait std::cmp::PartialOrd">PartialOrd</a><<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/cmp/trait.PartialOrd.html" title="trait std::cmp::PartialOrd">PartialOrd</a><T> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#811-902' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.partial_cmp' class="method"><span id='partial_cmp.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialOrd.html#tymethod.partial_cmp' class='fnname'>partial_cmp</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="enum" href="../../std/option/enum.Option.html" title="enum std::option::Option">Option</a><<a class="enum" href="../../std/cmp/enum.Ordering.html" title="enum std::cmp::Ordering">Ordering</a>></code></span></h4> <div class='docblock'><p>Partial comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code>partial_cmp()</code> on their inner values.</p> <h1 id='examples-16' class='section-header'><a href='#examples-16'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">cmp</span>::<span class="ident">Ordering</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="prelude-val">Some</span>(<span class="ident">Ordering</span>::<span class="ident">Less</span>), <span class="ident">five</span>.<span class="ident">partial_cmp</span>(<span class="kw-2">&</span><span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">6</span>)));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0Ause%20std%3A%3Acmp%3A%3AOrdering%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert_eq!(Some(Ordering%3A%3ALess)%2C%20five.partial_cmp(%26Rc%3A%3Anew(6)))%3B%0A%7D">Run</a></pre> </div><h4 id='method.lt' class="method"><span id='lt.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialOrd.html#method.lt' class='fnname'>lt</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>Less-than comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code><</code> on their inner values.</p> <h1 id='examples-17' class='section-header'><a href='#examples-17'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op"><</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">6</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20%3C%20Rc%3A%3Anew(6))%3B%0A%7D">Run</a></pre> </div><h4 id='method.le' class="method"><span id='le.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialOrd.html#method.le' class='fnname'>le</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>'Less than or equal to' comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code><=</code> on their inner values.</p> <h1 id='examples-18' class='section-header'><a href='#examples-18'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op"><=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20%3C%3D%20Rc%3A%3Anew(5))%3B%0A%7D">Run</a></pre> </div><h4 id='method.gt' class="method"><span id='gt.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialOrd.html#method.gt' class='fnname'>gt</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>Greater-than comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code>></code> on their inner values.</p> <h1 id='examples-19' class='section-header'><a href='#examples-19'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op">></span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">4</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20%3E%20Rc%3A%3Anew(4))%3B%0A%7D">Run</a></pre> </div><h4 id='method.ge' class="method"><span id='ge.v' class='invisible'><code>fn <a href='../../std/cmp/trait.PartialOrd.html#method.ge' class='fnname'>ge</a>(&self, other: &<a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T>) -> <a class="primitive" href="../primitive.bool.html">bool</a></code></span></h4> <div class='docblock'><p>'Greater than or equal to' comparison for two <code>Rc</code>s.</p> <p>The two are compared by calling <code>>=</code> on their inner values.</p> <h1 id='examples-20' class='section-header'><a href='#examples-20'>Examples</a></h1> <pre class="rust rust-example-rendered"> <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">rc</span>::<span class="ident">Rc</span>; <span class="kw">let</span> <span class="ident">five</span> <span class="op">=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>); <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">five</span> <span class="op">>=</span> <span class="ident">Rc</span>::<span class="ident">new</span>(<span class="number">5</span>));<a class="test-arrow" target="_blank" href="https://play.rust-lang.org/?code=fn%20main()%20%7B%0Ause%20std%3A%3Arc%3A%3ARc%3B%0A%0Alet%20five%20%3D%20Rc%3A%3Anew(5)%3B%0A%0Aassert!(five%20%3E%3D%20Rc%3A%3Anew(5))%3B%0A%7D">Run</a></pre> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/cmp/trait.Eq.html" title="trait std::cmp::Eq">Eq</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#808' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/convert/trait.From.html" title="trait std::convert::From">From</a><T> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.6.0'>1.6.0</div><a class='srclink' href='../../src/alloc/rc.rs.html#955-959' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.from' class="method"><span id='from.v' class='invisible'><code>fn <a href='../../std/convert/trait.From.html#tymethod.from' class='fnname'>from</a>(t: T) -> <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span></h4> <div class='docblock'><p>Performs the conversion.</p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T> !<a class="trait" href="../../std/marker/trait.Sync.html" title="trait std::marker::Sync">Sync</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#287' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div><h3 class='impl'><span class='in-band'><code>impl<T> <a class="trait" href="../../std/fmt/trait.Display.html" title="trait std::fmt::Display">Display</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T> <span class="where fmt-newline">where<br> T: <a class="trait" href="../../std/fmt/trait.Display.html" title="trait std::fmt::Display">Display</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>, </span></code></span><span class='out-of-band'><div class='ghost'></div><a class='srclink' href='../../src/alloc/rc.rs.html#934-938' title='goto source code'>[src]</a></span></h3> <div class='impl-items'><h4 id='method.fmt-2' class="method"><span id='fmt.v-2' class='invisible'><code>fn <a href='../../std/fmt/trait.Display.html#tymethod.fmt' class='fnname'>fmt</a>(&self, f: &mut <a class="struct" href="../../std/fmt/struct.Formatter.html" title="struct std::fmt::Formatter">Formatter</a>) -> <a class="enum" href="../../std/result/enum.Result.html" title="enum std::result::Result">Result</a><<a class="primitive" href="../primitive.tuple.html">()</a>, <a class="struct" href="../../std/fmt/struct.Error.html" title="struct std::fmt::Error">Error</a>></code></span></h4> <div class='docblock'><p>Formats the value using the given formatter. <a href="../../std/fmt/trait.Display.html#tymethod.fmt">Read more</a></p> </div></div><h3 class='impl'><span class='in-band'><code>impl<T: <a class="trait" href="../../std/panic/trait.RefUnwindSafe.html" title="trait std::panic::RefUnwindSafe">RefUnwindSafe</a> + ?<a class="trait" href="../../std/marker/trait.Sized.html" title="trait std::marker::Sized">Sized</a>> <a class="trait" href="../../std/panic/trait.UnwindSafe.html" title="trait std::panic::UnwindSafe">UnwindSafe</a> for <a class="struct" href="../../std/rc/struct.Rc.html" title="struct std::rc::Rc">Rc</a><T></code></span><span class='out-of-band'><div class='ghost'></div><div class='since' title='Stable since Rust version 1.9.0'>1.9.0</div><a class='srclink' href='../../src/std/panic.rs.html#215' title='goto source code'>[src]</a></span></h3> <div class='impl-items'></div></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>?</dt> <dd>Show this help dialog</dd> <dt>S</dt> <dd>Focus the search field</dd> <dt>⇤</dt> <dd>Move up in search results</dd> <dt>⇥</dt> <dd>Move down in search results</dd> <dt>⏎</dt> <dd>Go to active search result</dd> <dt>+</dt> <dd>Collapse/expand 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> </div> </div> </aside> <script> window.rootPath = "../../"; window.currentCrate = "std"; </script> <script src="../../main.js"></script> <script defer src="../../search-index.js"></script> </body> </html>