Result!()
macro
The syntax of Result!()
macro is
Result!( OkType throws Err1, Err2, .. )
, the underlying type of which is
Result<OkType, Enum!(Err1, Err2, ..)>
. However the Result!()
macro is
preferred over Enum!()
because:
-
Enum!()
is subject to changes on feature oflog
/env_log
, whileResult!()
is not. -
throws
is cool, shorter and more clear thanEnum!()
.
Use Result!()
to enumerate the possible error types
- in function signature:
#![allow(unused)] fn main() { #[cex] fn throws_never() -> Result!(i32) {/**/} struct SomeError; #[cex] fn foo() -> Result!( i32 throws String, &'static str, SomeError ) {/**/} }
- in closure's signature:
#![allow(unused)] fn main() { fn foo() { let _f = #[cex] || -> Result!( i32 throws String ) {/**/} } }
- in the type annotation of a local let-binding:
#![allow(unused)] fn main() { fn foo() { #[cex] let v: Result!( i32 throws String ) = try {/**/}; } }