::custom-try
Macro to customize the behavior of ?
Examples
use ::custom_try::custom_try;
#[repr(transparent)]
pub struct FfiResult {
pub status_code: ::std::os::raw::c_int,
}
impl FfiResult {
pub const OK: Self = Self { status_code: 0 };
pub const ERR: Self = Self { status_code: -1 };
}
macro_rules! unwrap_option {( $option:expr $(,)? ) => (
match $option {
Some(thing) => thing,
None => return FfiResult::ERR,
}
)}
#[custom_try(unwrap_option!)]
extern "C" fn ffi_function() -> FfiResult {
let x = the_answer_to_life_the_universe_and_everything()?;
println!("{}", x);
FfiResult::OK
}
/// If you only have one case of `?` semantics, you can default to that one
/// using the default `r#try!` macro name.
use unwrap_option as r#try;
#[custom_try]
extern "C" fn ffi_function2() -> FfiResult {
let x = the_answer_to_life_the_universe_and_everything()?;
println!("{}", x);
FfiResult::OK
}