OptionBool represents an optional boolean value, similar to
Option<bool>. Most function implementations are similar or equal.
Note that the
or_else_bool(..) functions are working similar to the
methods without the
_bool suffix, but require and return
Option<bool>. This allows people to stay within the type.
OptionBool type is expected to require only 1 byte of storage:
assert!(1 == std::mem::size_of::<optional::OptionBool>());
However, since this crate was originally authored, improvements in the
have built in this optimization for
Option<bool> as well. The
OptionBool type remains however because it may still perform faster in
some bench marks.
assert!(1 == std::mem::size_of::<Option<bool>>());
Then there is the
Optioned<T> type which wraps a type
T as an optional
T where one particular value represents None.
requires the exact same space as T:
assert!(std::mem::size_of::<optional::Optioned<i64>>() == std::mem::size_of::<i64>()); assert!(std::mem::size_of::<optional::Optioned<f32>>() == std::mem::size_of::<f32>()); assert!(std::mem::size_of::<optional::Optioned<u8>>() == std::mem::size_of::<u8>());
There are implementations for
representing None, also for
representing None, and for
f32, f64 with
Using Optioned for your own types is as simple as implementing
your type, provided that your type is already Copy and Sized.
iterate over an
iterate over an Optioned
A trait whose implementation for any type
Equality within Optioned
Ordering within Optioned