You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/trait/disambiguating.md
+7-5
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# Disambiguating overlapping traits
2
2
3
-
A type can implement many different traits. What if two traits both require the same name? For example, many traits might have a method named `get()`. They might even have different return types!
3
+
A type can implement many different traits. What if two traits both require
4
+
the same name? For example, many traits might have a method named `get()`.
5
+
They might even have different return types!
4
6
5
-
Good news: because each trait implementation gets its own `impl` block, it's
6
-
clear which trait's `get` method you're implementing.
7
+
Good news: because each trait implementation gets its own `impl` block, it's
8
+
clear which trait's `get` method you're implementing.
7
9
8
10
What about when it comes time to _call_ those methods? To disambiguate between
9
11
them, we have to use Fully Qualified Syntax.
@@ -38,12 +40,12 @@ impl AgeWidget for Form {
38
40
}
39
41
40
42
fn main() {
41
-
let form = Form{
43
+
let form = Form{
42
44
username: "rustacean".to_owned(),
43
45
age: 28,
44
46
};
45
47
46
-
// If you uncomment this line, you'll get an error saying
48
+
// If you uncomment this line, you'll get an error saying
47
49
// "multiple `get` found". Because, after all, there are multiple methods
0 commit comments