fluence_sdk_wit/
parse_macro_input.rs

1/*
2 * Copyright 2020 Fluence Labs Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17mod item_fn;
18mod item_foreign_mod;
19mod item_record;
20mod utils;
21
22use crate::ast_types::FCEAst;
23
24pub(crate) trait ParseMacroInput {
25    fn parse_macro_input(self) -> syn::Result<FCEAst>;
26}
27
28impl ParseMacroInput for syn::Item {
29    fn parse_macro_input(self) -> syn::Result<FCEAst> {
30        use syn::spanned::Spanned;
31
32        match self {
33            syn::Item::Fn(function) => function.parse_macro_input(),
34            syn::Item::ForeignMod(extern_mod) => extern_mod.parse_macro_input(),
35            syn::Item::Struct(item_struct) => item_struct.parse_macro_input(),
36            _ => Err(syn::Error::new(
37                self.span(),
38                "At now, #[fce] could be applied only to a function, extern block or struct",
39            )),
40        }
41    }
42}