| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations |
| 6 |
// #![cfg_attr(not(any(test, doc)), no_std)] |
| 7 |
// #![cfg_attr( |
| 8 |
// not(test), |
| 9 |
// deny( |
| 10 |
// clippy::indexing_slicing, |
| 11 |
// clippy::unwrap_used, |
| 12 |
// clippy::expect_used, |
| 13 |
// clippy::panic, |
| 14 |
// ) |
| 15 |
// )] |
| 16 |
#![warn(missing_docs)] |
| 17 |
|
| 18 |
//! Proc macros for generating `ULE`, `VarULE` impls and types for the `zerovec` crate |
| 19 |
|
| 20 |
use proc_macro::TokenStream; |
| 21 |
use syn::{parse_macro_input, DeriveInput, Ident}; |
| 22 |
mod make_ule; |
| 23 |
mod make_varule; |
| 24 |
pub(crate) mod ule; |
| 25 |
mod utils; |
| 26 |
mod varule; |
| 27 |
|
| 28 |
/// Full docs for this proc macro can be found on the [`zerovec`](https://docs.rs/zerovec) crate. |
| 29 |
#[proc_macro_derive(ULE)] |
| 30 |
pub fn ule_derive(input: TokenStream) -> TokenStream { |
| 31 |
let input = parse_macro_input!(input as DeriveInput); |
| 32 |
TokenStream::from(ule::derive_impl(&input)) |
| 33 |
} |
| 34 |
|
| 35 |
/// Full docs for this proc macro can be found on the [`zerovec`](https://docs.rs/zerovec) crate. |
| 36 |
#[proc_macro_derive(VarULE)] |
| 37 |
pub fn varule_derive(input: TokenStream) -> TokenStream { |
| 38 |
let input = parse_macro_input!(input as DeriveInput); |
| 39 |
TokenStream::from(varule::derive_impl(&input, None)) |
| 40 |
} |
| 41 |
|
| 42 |
/// Full docs for this proc macro can be found on the [`zerovec`](https://docs.rs/zerovec) crate. |
| 43 |
#[proc_macro_attribute] |
| 44 |
pub fn make_ule(attr: TokenStream, item: TokenStream) -> TokenStream { |
| 45 |
let input = parse_macro_input!(item as DeriveInput); |
| 46 |
let attr = parse_macro_input!(attr as Ident); |
| 47 |
TokenStream::from(make_ule::make_ule_impl(attr, input)) |
| 48 |
} |
| 49 |
|
| 50 |
/// Full docs for this proc macro can be found on the [`zerovec`](https://docs.rs/zerovec) crate. |
| 51 |
#[proc_macro_attribute] |
| 52 |
pub fn make_varule(attr: TokenStream, item: TokenStream) -> TokenStream { |
| 53 |
let input = parse_macro_input!(item as DeriveInput); |
| 54 |
let attr = parse_macro_input!(attr as Ident); |
| 55 |
TokenStream::from(make_varule::make_varule_impl(attr, input)) |
| 56 |
} |