mirror of
https://github.com/rust-unofficial/patterns
synced 2024-11-10 13:10:30 +00:00
deploy: 90484a2387
This commit is contained in:
parent
74eaa27fc6
commit
2ae0b1b1a0
@ -163,14 +163,14 @@ let mut x = 5;
|
|||||||
// Borrow `x` -- but clone it first
|
// Borrow `x` -- but clone it first
|
||||||
let y = &mut (x.clone());
|
let y = &mut (x.clone());
|
||||||
|
|
||||||
// perform some action on the borrow to prevent rust from optimizing this
|
|
||||||
//out of existence
|
|
||||||
*y += 1;
|
|
||||||
|
|
||||||
// without the x.clone() two lines prior, this line would fail on compile as
|
// without the x.clone() two lines prior, this line would fail on compile as
|
||||||
// x has been borrowed
|
// x has been borrowed
|
||||||
// thanks to x.clone(), x was never borrowed, and this line will run.
|
// thanks to x.clone(), x was never borrowed, and this line will run.
|
||||||
println!("{}", x);
|
println!("{}", x);
|
||||||
|
|
||||||
|
// perform some action on the borrow to prevent rust from optimizing this
|
||||||
|
//out of existence
|
||||||
|
*y += 1;
|
||||||
<span class="boring">}
|
<span class="boring">}
|
||||||
</span></code></pre></pre>
|
</span></code></pre></pre>
|
||||||
<h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
|
<h2 id="motivation"><a class="header" href="#motivation">Motivation</a></h2>
|
||||||
|
@ -3043,14 +3043,14 @@ let mut x = 5;
|
|||||||
// Borrow `x` -- but clone it first
|
// Borrow `x` -- but clone it first
|
||||||
let y = &mut (x.clone());
|
let y = &mut (x.clone());
|
||||||
|
|
||||||
// perform some action on the borrow to prevent rust from optimizing this
|
|
||||||
//out of existence
|
|
||||||
*y += 1;
|
|
||||||
|
|
||||||
// without the x.clone() two lines prior, this line would fail on compile as
|
// without the x.clone() two lines prior, this line would fail on compile as
|
||||||
// x has been borrowed
|
// x has been borrowed
|
||||||
// thanks to x.clone(), x was never borrowed, and this line will run.
|
// thanks to x.clone(), x was never borrowed, and this line will run.
|
||||||
println!("{}", x);
|
println!("{}", x);
|
||||||
|
|
||||||
|
// perform some action on the borrow to prevent rust from optimizing this
|
||||||
|
//out of existence
|
||||||
|
*y += 1;
|
||||||
<span class="boring">}
|
<span class="boring">}
|
||||||
</span></code></pre></pre>
|
</span></code></pre></pre>
|
||||||
<h2 id="motivation-17"><a class="header" href="#motivation-17">Motivation</a></h2>
|
<h2 id="motivation-17"><a class="header" href="#motivation-17">Motivation</a></h2>
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user