In Chapter 2, Sequential Rust Performance and Testing, we very briefly dipped into the implementation of std::collections::HashMap
. Let's continue with that approach of dissecting the standard library, paying special attention to the concerns of memory that pop up.
Let's examine Option<T>
. We've already discussed Option<T>
in this chapter; that it's subject to null pointer optimization on account of its empty None
variant in particular. Option
is as simple as you might imagine, being defined in src/libcore/option.rs
:
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub enum Option<T> { /// No value #[stable(feature = "rust1", since = "1.0.0")] None, /// Some value `T` #[stable(feature = "rust1", since = "1.0.0")] Some(#[stable(feature = "rust1", since = "1.0.0")] T), }
As is often the case with Rust internals, there are a great deal of flags around to control when...