File tree Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Expand file tree Collapse file tree 1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -109,19 +109,28 @@ Here’s an example of using the longer form.
109
109
110
110
``` rust
111
111
trait Foo {
112
- fn clone ( & self ) ;
112
+ fn foo () -> i32 ;
113
113
}
114
114
115
- #[derive(Clone )]
116
115
struct Bar ;
117
116
118
- impl Foo for Bar {
119
- fn clone (& self ) {
120
- println! (" Making a clone of Bar" );
117
+ impl Bar {
118
+ fn foo () -> i32 {
119
+ 20
120
+ }
121
+ }
121
122
122
- <Bar as Clone >:: clone (self );
123
+ impl Foo for Bar {
124
+ fn foo () -> i32 {
125
+ 10
123
126
}
124
127
}
128
+
129
+ fn main () {
130
+ assert_eq! (10 , <Bar as Foo >:: foo ());
131
+ assert_eq! (20 , Bar :: foo ());
132
+ }
125
133
```
126
134
127
- This will call the ` Clone ` trait’s ` clone() ` method, rather than ` Foo ` ’s.
135
+ Using the angle bracket syntax lets you call the trait method instead of the
136
+ inherent one.
You can’t perform that action at this time.
0 commit comments