Exploring std and the prelude module
In previous chapters, we used built-in modules such as str
, vec
, and io
from the std
crate. The std
crate contains many modules and functions that are used in real projects. For that reason, you won't see extern crate std
, because std
is imported by default in every other crate.
The small prelude
module in std
declares mostly traits (such as Copy
, Send
, Sync
, Drop
, Clone
, Eq
, Ord
, and so on) and common types (such as Option
and Result
). For the same reason, the contents of the prelude
module are imported by default in every module, as well as a number of standard macros (such as println!
). That is the reason why we don't need to specify Result::
before the Ok
and Err
variants in match
branches.
The website https://doc.rust-lang.org/std/ shows lists of the primitive types, modules, and macros contained in the standard library. We already discussed the most important macros from the standard library; see Chapter 5, Higher-Order Functions and Error-Handlin...