cosmwasm_schema_derive/
error.rs

1macro_rules! bail {
2    ($span_src:expr, $msg:literal) => {{
3        return Err($crate::error::error_message!($span_src, $msg));
4    }};
5}
6
7macro_rules! error_message {
8    ($span_src:expr, $msg:literal) => {{
9        ::syn::Error::new(::syn::spanned::Spanned::span(&{ $span_src }), $msg)
10    }};
11}
12
13macro_rules! fallible_macro {
14    (
15        $(
16            #[ $( $attribute_decl:tt )* ]
17        )*
18        pub fn $macro_name:ident ( $( $params:tt )* ) -> syn::Result<$inner_return:path> {
19            $( $fn_body:tt )*
20        }
21    ) => {
22        $(
23            #[ $( $attribute_decl )* ]
24        )*
25        pub fn $macro_name ( $( $params )* ) -> $inner_return {
26            let result = move || -> ::syn::Result<_> {
27                $( $fn_body )*
28            };
29
30            match result() {
31                Ok(val) => val,
32                Err(err) => err.into_compile_error().into(),
33            }
34        }
35    }
36}
37
38pub(crate) use bail;
39pub(crate) use error_message;
40pub(crate) use fallible_macro;