987 B
987 B
Traits
In the previous chapter we covered the basics of Rust’s type and
ownership system.
It’s time to dig deeper: we’ll explore traits, Rust’s
take on interfaces.
Once you learn about traits, you’ll start seeing their fingerprints
all over the place.
In fact, you’ve already seen traits in action throughout the previous
chapter, e.g. .into() invocations as well as operators like
== and +.
On top of traits as a concept, we’ll also cover some of the key traits that are defined in Rust’s standard library:
- Operator traits (e.g.
Add,Sub,PartialEq, etc.) FromandInto, for infallible conversionsCloneandCopy, for copying valuesDerefand deref coercionSized, to mark types with a known sizeDrop, for custom cleanup logic
Since we’ll be talking about conversions, we’ll seize the opportunity
to plug some of the “knowledge gaps” from the previous chapter—e.g. what
is "A title", exactly? Time to learn more about slices
too!