summaryrefslogtreecommitdiffstats
path: root/vendor/zerovec-derive/src/lib.rs
blob: 5a0de64298287f82983cab2858398513a72573d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Proc macros for generating `ULE`, `VarULE` impls and types for the `zerovec` crate

use proc_macro::TokenStream;
use syn::{parse_macro_input, AttributeArgs, DeriveInput};

mod make_ule;
mod make_varule;
pub(crate) mod ule;
mod utils;
mod varule;

/// Full docs for this proc macro can be found on the [`zerovec`](docs.rs/zerovec) crate.
#[proc_macro_derive(ULE)]
pub fn ule_derive(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    TokenStream::from(ule::derive_impl(&input))
}

/// Full docs for this proc macro can be found on the [`zerovec`](docs.rs/zerovec) crate.
#[proc_macro_derive(VarULE)]
pub fn varule_derive(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    TokenStream::from(varule::derive_impl(&input, None))
}

/// Full docs for this proc macro can be found on the [`zerovec`](docs.rs/zerovec) crate.
#[proc_macro_attribute]
pub fn make_ule(attr: TokenStream, item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let attr = parse_macro_input!(attr as AttributeArgs);
    TokenStream::from(make_ule::make_ule_impl(attr, input))
}

/// Full docs for this proc macro can be found on the [`zerovec`](docs.rs/zerovec) crate.
#[proc_macro_attribute]
pub fn make_varule(attr: TokenStream, item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let attr = parse_macro_input!(attr as AttributeArgs);
    TokenStream::from(make_varule::make_varule_impl(attr, input))
}