dialtone_sqlx_macros/lib.rs
1mod sqlx_enum_proxy;
2
3use crate::sqlx_enum_proxy::expand_sqlx_enum_proxy;
4use proc_macro::TokenStream;
5use syn::{parse_macro_input, DeriveInput};
6
7/// This macro defines FromStr, ToStr, and Into implementations
8/// for enums based on another enum. Therefore, the derived enum
9/// can proxy for the base enum. The purpose of this is to allow
10/// the proxy to track the base enum allowing the base enum to
11/// be free of the sqlx types (and therefore, its containing crate
12/// will not need the sqlx dependency). This is useful if the base
13/// enum is used in a different tier of the application, such as in
14/// client side webapps.
15#[proc_macro_derive(SqlxEnumProxy, attributes(proxy_for))]
16pub fn sqlx_enum_proxy(input: TokenStream) -> TokenStream {
17 let input = parse_macro_input!(input as DeriveInput);
18 expand_sqlx_enum_proxy(input)
19 .unwrap_or_else(syn::Error::into_compile_error)
20 .into()
21}