option-operations CI

option-operations provides traits and auto-implementations to improve arithmetic operations usability when dealing with Options.

Example

Dealing with two Options, can lead to verbose expressions:

``` rust let lhs = Some(1u64); let rhs = Some(u64::MAX);

asserteq!( lhs.zip(rhs).map(|(lhs, rhs)| lhs.wrappingadd(rhs)), Some(0), ); ```

Thanks to the trait OptionWrappingAdd we can write:

rust assert_eq!( lhs.opt_wrapping_add(rhs), Some(0), );

The trait can also be used with the inner type:

``` rust asserteq!( lhs.optwrapping_add(u64::MAX), Some(0), );

asserteq!( 1.optwrapping_add(rhs), Some(0), ); ```

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:

``` rust let some_0 = Some(0); let none: Option = None;

asserteq!(none.partialcmp(&some0), Some(Ordering::Less)); asserteq!(some0.partialcmp(&none), Some(Ordering::Greater)); ```

In some cases, we might consider that None reflects a value which is not defined and thus can not be compared with Some(_).

rust assert_eq!(none.opt_cmp(&some_0), None); assert_eq!(some_0.opt_cmp(&none), None);

LICENSE

This crate is licensed under either of

at your option.