Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
programming:rust [2020/12/13 18:15] – [Traits] mh | programming:rust [2020/12/13 18:35] – [Traits] mh | ||
---|---|---|---|
Line 494: | Line 494: | ||
</ | </ | ||
- | Each type implementing the '' | + | Each type implementing the '' |
To implement a trait on a type : | To implement a trait on a type : | ||
Line 505: | Line 505: | ||
} | } | ||
</ | </ | ||
+ | |||
+ | If the trait had a default behavior, this implementation will override it. | ||
+ | |||
+ | Default implementations can also call other methods in the same trait, even if those other methods don't have a default implementation. | ||
+ | |||
+ | === Traits as Parameters === | ||
+ | |||
+ | Traits can be used to define functions that accept many different types who all implement a certain trait. The function is defined using that trait as a parameter, instead of concrete types. [[https:// | ||
+ | |||
+ | === Blanket implementations === | ||
+ | |||
+ | They are extensively used in the Rust Standard librarby and allow implementing a trait for any type that implements another trait. [[https:// | ||
===== Misc ===== | ===== Misc ===== | ||