cw_schema_derive/
lib.rs

1//! Derive macros for cw-schema. For internal use only.
2//!
3//! CosmWasm is a smart contract platform for the Cosmos ecosystem.
4//! For more information, see: <https://cosmwasm.cosmos.network>
5
6mod expand;
7
8macro_rules! bail {
9    ($span_src:expr, $msg:literal) => {{
10        return Err($crate::error_message!($span_src, $msg));
11    }};
12}
13
14macro_rules! error_message {
15    ($span_src:expr, $msg:literal) => {{
16        ::syn::Error::new(::syn::spanned::Spanned::span(&{ $span_src }), $msg)
17    }};
18}
19// Needed so we can import macros. Rust, why?
20use {bail, error_message};
21
22#[proc_macro_derive(Schemaifier, attributes(schemaifier, serde))]
23pub fn schemaifier(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
24    let input = syn::parse_macro_input!(input as syn::DeriveInput);
25
26    match expand::expand(input) {
27        Ok(output) => output.into(),
28        Err(err) => err.to_compile_error().into(),
29    }
30}