pub struct Fallback<T> { /* private fields */ }
Expand description
Stores two Option, and provides functionality to fallback.
Basically, you provides a function returns Option,
and Fallback handles the fallback.
let data = Some("hello");
let base_data = Some("123");
let fallback = Fallback::new(data, base_data);
let num = fallback.and_then(|s| s.parse::<i32>().ok());
assert_eq!(num, Some(123));
And you can map the Fallback:
let data = Some(123);
let base_data = Some(123456);
let fallback = Fallback::new(data, base_data);
let fallback = fallback.map(|i| i.to_string());
let s = fallback.and_then(|s| if s.len() > 3 { Some(s) } else { None });
assert_eq!(s, Some("123456".to_string()));
Returns false if both data and base_data are None.
Converts from &Fallback<T> to Fallback<&T>.
Fallbacks the data or part of data.
Fallbacks the total data.
Exacts the data and base_data.
Converts from Fallback<Option<T>> to Fallback<T>.
Treats the empty container as None and fallbacks.
Get the specialized fallback object.
Converts to this type from the input type.
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Immutably borrows from an owned value.
Read more
Mutably borrows from an owned value.
Read more
Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From<T> for U chooses to do.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.