For Option types, I frequently use the ok_or combinator to return errors like this:
let my_vec = [1,2,3];
let head = my_vec.first().cloned().ok_or(Error::MyError)?;
I am looking for a similar combinator or method to handle boolean values not Option types. For example:
let my_vec = [1,2,3];
let head = my_vec.is_empty().false_or(Error::MyError)?;
I often write matches to handle this, but it seems quite verbose:
let vec_is_ok = match my_vec.is_empty() {
true => Err(...),
false => Ok(())
}
vec_is_ok?;
Is there are more concise way to write this similar to the ok_or combinator that i can use on boolean values?