move_syn/functions/
mod.rs1use cfg_if::cfg_if;
2use unsynn::*;
3
4use crate::{Generics, kw};
5
6#[cfg(feature = "fun-sig")]
7mod signature;
8
9unsynn! {
10 pub struct Function {
11 entry: Option<kw::Entry>,
12 fun_kw: kw::Fun,
13 ident: Ident,
14 generics: Option<Generics>,
15 args: Arguments,
16 ret: Option<Returns>,
17 body: BraceGroup,
18 }
19
20 pub struct NativeFun {
21 native_kw: kw::Native,
22 fun_kw: kw::Fun,
23 ident: Ident,
24 generics: Option<Generics>,
25 args: Arguments,
26 ret: Option<Returns>,
27 semicolon: Semicolon
28 }
29}
30
31cfg_if!(if #[cfg(feature = "fun-sig")] {
32 use self::signature::Arguments;
33 use self::signature::Returns;
34} else {
35 type Arguments = ParenthesisGroup;
36
37 unsynn! {
38 struct Returns {
40 colon: Colon,
41 type_: ReturnType,
42 }
43
44 enum ReturnType {
45 One(crate::MaybeRefType),
46 Many(ParenthesisGroup)
47 }
48 }
49});
50
51impl Function {
52 pub const fn is_entry(&self) -> bool {
53 self.entry.is_some()
54 }
55
56 pub const fn ident(&self) -> &Ident {
57 &self.ident
58 }
59
60 pub const fn generics(&self) -> Option<&Generics> {
61 self.generics.as_ref()
62 }
63}
64
65impl NativeFun {
66 pub const fn ident(&self) -> &Ident {
67 &self.ident
68 }
69
70 pub const fn generics(&self) -> Option<&Generics> {
71 self.generics.as_ref()
72 }
73}