Crate optional [−] [src]
Space-efficient optional values
Type OptionBool
represents an optional boolean value, similar to
Option<bool>
. Most function implementations are similar or equal.
Note that the map_bool(..)
and_bool(..)
, and_then_bool(..)
,
or_bool(..)
and or_else_bool(..)
functions are working similar to the
methods without the _bool
suffix, but require and return OptionBool
instead of Option<bool>
. This allows people to stay within the type.
The OptionBool
type is expected to require only 1 byte of storage:
assert!(1 == std::mem::size_of::<optional::OptionBool>());
Then there is the Optioned<T>
type which wraps a type T
as an optional
value of T
where one particular value represents None. Optioned<T>
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 u8..64,usize
with std::u..::MAX
representing None, also for i8..64,isize
with std::i..::MIN
representing None, and for f32, f64
with std::f..::NAN
representing
None.
Using Optioned for your own types is as simple as implementing Noned
for
your type, provided that your type is already Copy and Sized.
Structs
IterBool |
iterate over an OptionBool |
Optioned |
An |
OptionedIter |
iterate over an Optioned |
Enums
OptionBool |
The |
Traits
Noned |
A trait whose implementation for any type |
OptEq |
Equality within Optioned |
OptOrd |
Ordering within Optioned |
Functions
none |
Create a |
some |
Create an |
wrap |
Wrap a |