mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:34:32 -06:00
rebuild pages at 830db27
This commit is contained in:
@@ -222,7 +222,7 @@ reference. Yet, we needed a <code>&</code> for <code>p2</code> but not <code
|
||||
<p>This feature is called ‘automatic referencing’, and calling methods is one
|
||||
of the few places in Rust that has behavior like this. Here’s how it works:
|
||||
when you call a method with <code>self.(</code>, Rust will automatically add in <code>&</code>s
|
||||
or <code>&mut</code>s to match the signature. In other words, these are the same:</p>
|
||||
or <code>&mut</code>s to match the signature. In other words, these three are the same:</p>
|
||||
<pre><code class="language-rust"># #[derive(Debug,Copy,Clone)]
|
||||
# struct Point {
|
||||
# x: f64,
|
||||
@@ -241,6 +241,7 @@ or <code>&mut</code>s to match the signature. In other words, these are the
|
||||
# let p2 = Point { x: 5.0, y: 6.5 };
|
||||
p1.distance(&p2);
|
||||
(&p1).distance(&p2);
|
||||
Point::distance(&p1, &p2);
|
||||
</code></pre>
|
||||
<p>The first one looks much, much cleaner. Here’s another example:</p>
|
||||
<pre><code class="language-rust">let mut s = String::from("Hello,");
|
||||
|
||||
+2
-1
@@ -2950,7 +2950,7 @@ reference. Yet, we needed a <code>&</code> for <code>p2</code> but not <code
|
||||
<p>This feature is called ‘automatic referencing’, and calling methods is one
|
||||
of the few places in Rust that has behavior like this. Here’s how it works:
|
||||
when you call a method with <code>self.(</code>, Rust will automatically add in <code>&</code>s
|
||||
or <code>&mut</code>s to match the signature. In other words, these are the same:</p>
|
||||
or <code>&mut</code>s to match the signature. In other words, these three are the same:</p>
|
||||
<pre><code class="language-rust"># #[derive(Debug,Copy,Clone)]
|
||||
# struct Point {
|
||||
# x: f64,
|
||||
@@ -2969,6 +2969,7 @@ or <code>&mut</code>s to match the signature. In other words, these are the
|
||||
# let p2 = Point { x: 5.0, y: 6.5 };
|
||||
p1.distance(&p2);
|
||||
(&p1).distance(&p2);
|
||||
Point::distance(&p1, &p2);
|
||||
</code></pre>
|
||||
<p>The first one looks much, much cleaner. Here’s another example:</p>
|
||||
<pre><code class="language-rust">let mut s = String::from("Hello,");
|
||||
|
||||
Reference in New Issue
Block a user