summaryrefslogtreecommitdiffstats
path: root/src/doc/book/redirects/ufcs.md
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/doc/book/redirects/ufcs.md
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/doc/book/redirects/ufcs.md')
-rw-r--r--src/doc/book/redirects/ufcs.md48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/doc/book/redirects/ufcs.md b/src/doc/book/redirects/ufcs.md
new file mode 100644
index 000000000..2959c06bd
--- /dev/null
+++ b/src/doc/book/redirects/ufcs.md
@@ -0,0 +1,48 @@
+% Universal Function Call Syntax
+
+<small>There is a new edition of the book and this is an old link.</small>
+
+> Rust cannot prevent a trait from having a method with the same name as another trait’s method, nor can it prevent us from implementing both of these traits on one type.
+> In order to be able to call each of the methods with the same name, then, we need to tell Rust which one we want to use.
+
+```rust
+trait Pilot {
+ fn fly(&self);
+}
+
+trait Wizard {
+ fn fly(&self);
+}
+
+struct Human;
+
+impl Pilot for Human {
+# fn fly(&self) {
+# println!("This is your captain speaking.");
+# }
+}
+
+impl Wizard for Human {
+# fn fly(&self) {
+# println!("Up!");
+# }
+}
+
+impl Human {
+# fn fly(&self) {
+# println!("*waving arms furiously*");
+# }
+}
+
+fn main() {
+ let person = Human;
+ Pilot::fly(&person);
+ Wizard::fly(&person);
+ person.fly();
+}
+```
+
+---
+
+You can find the latest version of this information
+[here](ch19-03-advanced-traits.html#fully-qualified-syntax-for-disambiguation-calling-methods-with-the-same-name). \ No newline at end of file