Module omaha_client::unless

source ·
Expand description

The Unless trait for a more fluent use of Option::unwrap_or().

Specificially, this is intended to be used in cases where the “default” value is almost always the value in use, and the Option is rarely set.

use omaha_client::unless::Unless;
// This implies that |some_option| is usually set, and "default" is there in case it's not.
let some_option_usually_set = Some("string");
let value = some_option_usually_set.unwrap_or("default");
assert_eq!("string", value);

// Whereas this implies that "default" is the common case, and |some_option| is an override.
let some_option_usually_unset = None;
let value = "default".unless(some_option_usually_unset);
assert_eq!("default", value);