All what I'm looking for is to have one-liner like:
assert!( 1 == 2 );
but instead of panic, want to just return MyErr().
For now I implement this way:
(1==2).then(|| ()).ok_or(MyErr())?;
Is there a cleaner way to do the same?
All what I'm looking for is to have one-liner like:
assert!( 1 == 2 );
but instead of panic, want to just return MyErr().
For now I implement this way:
(1==2).then(|| ()).ok_or(MyErr())?;
Is there a cleaner way to do the same?
As @Krish mentioned, use an
ifstatement here. For reference, this is also whatbool.thenbasically does: