range_derive/
lib.rs

1extern crate proc_macro;
2
3use proc_macro::TokenStream;
4use quote::quote;
5
6/// The derive macro #[derive(Range)] is used to implement the Range trait by default for a struct.\
7/// By default the range trait will not add any range to the Query.
8#[proc_macro_derive(Range)]
9pub fn range_derive(input: TokenStream) -> TokenStream {
10    let ast = syn::parse(input).unwrap();
11    impl_range_derive(&ast)
12}
13
14fn impl_range_derive(ast: &syn::DeriveInput) -> TokenStream {
15    let name = &ast.ident;
16    let gen = quote! {
17        impl Range for #name {
18            fn pattern(mut self, pattern: impl ToString) -> Self {
19                self
20            }
21
22            fn range(mut self, property: impl ToString, min: impl ToString, max: impl ToString) -> Self {
23                self
24            }
25        }
26    };
27    gen.into()
28}