File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -73,12 +73,25 @@ impl<T> Timestamped<T> {
73
73
}
74
74
75
75
impl <T > PartialEq for Timestamped <T >
76
- where T : PartialEq {
76
+ where
77
+ T : PartialEq ,
78
+ {
79
+ fn eq (& self , other : & Self ) -> bool {
80
+ self . value == other . value && self . timestamp == other . timestamp
81
+ }
82
+ }
83
+ ```
84
+
85
+ A shortcut for ` where ` clauses that exists in Rust is constraining the parameters
86
+ directly at their declaration:
87
+ ``` rust
88
+ impl <T : PartialEq > PartialEq for Timestamped <T > {
77
89
fn eq (& self , other : & Self ) -> bool {
78
90
self . value == other . value && self . timestamp == other . timestamp
79
91
}
80
92
}
81
93
```
94
+ Although ` where ` clauses are somewhat more powerful, since they can constrain arbitrary types (e.g. ` i32: PartialEq<T> ` ).
82
95
83
96
Generic type constraints are called [ bounds] [ bounds.rs ] in Rust.
84
97
You can’t perform that action at this time.
0 commit comments