#ternary #catch #marco #some

op

a simple library for operator

3 releases

0.1.3 Feb 22, 2024
0.1.2 Jan 20, 2024
0.1.0 Jan 5, 2024

#4 in #catch

Unlicense

5KB
90 lines

a simple library for operator

Example - Ternary

use op::ternary;
let n = ternary!(true => 0; 1);
assert_eq!(n, 0);
let n = ternary!(false => 0; 1);
assert_eq!(n, 1);

Example - catch

use op::catch;

let result1: Result<i32, i32> = Ok(1);
let result2: Result<i32, i32> = Ok(2);
assert_eq!(Ok(3), catch!(i32 -> Ok(result1? + result2?)));

let option1: Option<i32> = Some(1);
let option2: Option<i32> = Some(2);
assert_eq!(Some(3), catch!(Some(option1? + option2?)));

No runtime deps