floccus_proc/
lib.rs

1//! Procedural macros for floccus.
2//! 
3//! This crate contains procedural attribute macros (currently only one) used by the
4//! [floccus](https://crates.io/crates/floccus). But potentially can be used in some
5//! other crates, although will never be adapted to work with any other crate.
6//! 
7//! Source code of this crate is a modified copy of [derive-name-macros](https://crates.io/crates/derive-name-macros).
8
9use proc_macro::TokenStream;
10use quote::quote;
11use syn::{self};
12
13#[proc_macro_derive(Name)]
14pub fn name(input: TokenStream) -> TokenStream {
15    let ast: syn::DeriveInput = syn::parse_macro_input!(input);
16    let ident = &ast.ident;
17    let gen = quote! {
18        impl crate::quantities::QuantityName for #ident {
19            fn type_name_as_str() -> &'static str {
20                stringify!(#ident)
21            }
22        }
23    };
24    gen.into()
25}