Science is nothing else than the search to discover unity in the wild variety of nature—or, more exactly, in the variety of our experience. Poetry, painting, the arts are the same search, in Coleridge’s phrase, for unity in variety.
Apart from operator overloading, which we covered in the previous chapter, several other built-in traits let you hook into parts of the Rust language and standard library:
You can use the
Drop trait to clean up values when they go out of scope, like destructors in C++.
Smart pointer types, like
Rc<T>, can implement the
Deref trait to make the pointer reflect the methods of the wrapped value.
By implementing the
Into<T> traits, you can tell Rust how to convert a value from one type to another.
This chapter is a grab bag of useful traits from the Rust standard library. We’ll cover each of the traits shown in Table 13-1.
There are other important standard library traits as well. We’ll cover
IntoIterator in Chapter 15. The
Hash trait, for computing hash codes, is covered in Chapter 16. And a pair of traits that mark thread-safe types,
Sync, are covered in Chapter 19.
||Destructors. Cleanup code that Rust runs automatically whenever a value is dropped.|
||Marker trait for types with a fixed size known at compile time, as opposed to types (such as slices) that are dynamically sized. ...|