amplify_syn/
lib.rs

1// Rust language amplification derive library providing multiple generic trait
2// implementations, type wrappers, derive macros and other language enhancements
3//
4// Written in 2019-2021 by
5//     Dr. Maxim Orlovsky <orlovsky@pandoracore.com>
6//
7// To the extent possible under law, the author(s) have dedicated all
8// copyright and related and neighboring rights to this software to
9// the public domain worldwide. This software is distributed without
10// any warranty.
11//
12// You should have received a copy of the MIT License
13// along with this software.
14// If not, see <https://opensource.org/licenses/MIT>.
15
16//! Amplifying Rust language capabilities: helper functions for creating proc
17//! macro libraries
18//!
19//! # Examples
20//!
21//! `#[name]` - single form
22//! `#[name = "literal"]` - optional single value
23//! `#[name = TypeName]` - path value
24//! `#[name("literal", TypeName, arg = value)]` - list of arguments
25
26#![deny(
27    non_upper_case_globals,
28    non_camel_case_types,
29    non_snake_case,
30    unused_mut,
31    unused_imports,
32    missing_docs,
33    dead_code
34)]
35#![allow(clippy::large_enum_variant)]
36
37#[macro_use]
38extern crate quote;
39#[macro_use]
40extern crate syn;
41extern crate proc_macro;
42
43mod attr;
44mod cls;
45mod error;
46mod parsers;
47mod req;
48mod val;
49mod data;
50
51pub use attr::{Attr, ExtractAttr, ParametrizedAttr, SingularAttr};
52pub use cls::{LiteralClass, TypeClass, ValueClass};
53pub use data::{
54    DataInner, DataType, DeriveInner, Element, EnumKind, Field, FieldKind, Fields, Items,
55    NamedField, Scope, Variant, Vis,
56};
57pub use error::Error;
58pub use parsers::{MetaArg, MetaArgList, MetaArgNameValue};
59pub use req::{ArgValueReq, AttrReq, ListReq, ValueReq};
60pub use val::ArgValue;
61
62/// Convenience macro for constructing [`struct@syn::Ident`] from literals
63#[macro_export]
64macro_rules! ident {
65    ($ident:ident) => {
66        ::syn::Ident::new(stringify!($ident), ::proc_macro2::Span::call_site())
67    };
68}
69
70/// Convenience macro for constructing [`struct@syn::Path`] from literals
71#[macro_export]
72macro_rules! path {
73    ($ident:ident) => {
74        ::syn::Path::from(ident!($ident))
75    };
76}
77
78#[cfg(test)]
79mod test {
80    use proc_macro2::Span;
81    use syn::Ident;
82
83    #[test]
84    fn ident() {
85        assert_eq!(ident!(u8), Ident::new("u8", Span::call_site()));
86    }
87}