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