unwrap_enum_proc_macro/
lib.rs

1// Copyright (C) 2024 John Turner
2
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see <https://www.gnu.org/licenses/>.
15
16#![deny(clippy::pedantic, clippy::use_self)]
17#![allow(clippy::missing_panics_doc)]
18
19mod unwrap_enum;
20
21#[proc_macro_derive(EnumIs)]
22pub fn enum_is(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
23    let parsed_input = syn::parse_macro_input!(input as syn::DeriveInput);
24    match unwrap_enum::expand_enum_is(&parsed_input) {
25        Ok(output) => output.into(),
26        Err(e) => e.into_compile_error().into(),
27    }
28}
29
30#[proc_macro_derive(EnumAs)]
31pub fn enum_as(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
32    let parsed_input = syn::parse_macro_input!(input as syn::DeriveInput);
33    match unwrap_enum::expand_enum_as(&parsed_input, false) {
34        Ok(output) => output.into(),
35        Err(e) => e.into_compile_error().into(),
36    }
37}
38
39#[allow(unused_variables)]
40#[proc_macro_derive(EnumAsMut)]
41pub fn enum_as_mut(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
42    todo!()
43}
44
45#[allow(unused_variables)]
46#[proc_macro_derive(EnumInto)]
47pub fn enum_into(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
48    todo!()
49}