option-operations
option-operations
provides traits and auto-implementations to
improve arithmetic operations usability when dealing with Option
s.
Example
Dealing with two Option
s, can lead to verbose expressions:
let lhs = Some;
let rhs = Some;
assert_eq!;
Thanks to the trait OptionSaturatingAdd
we can write:
assert_eq!;
The trait can also be used with the inner type:
assert_eq!;
assert_eq!;
Alternative to PartialOrd
for Option<T>
Another purpose is to workaround the PartiaOrd
implementation
for Option<T>
, which uses the declaration order of the variants
for Option
. None
appearing before Some(_)
, it results in
the following behavior:
let some_0 = Some;
let none: = None;
assert_eq!;
assert_eq!;
In some cases, we might consider that None
reflects a value which
is not defined and thus can not be compared with Some(_)
.
assert_eq!;
assert_eq!;
Of course, this is consistent with other usual comparisons:
assert_eq!;
assert_eq!;
LICENSE
This crate is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.