blob: c5cc1de72a25c24c988f0b408a35118aeaa4c4d6 [file] [log] [blame]
David Tolnay7db73692019-10-20 14:51:12 -04001// Functionality that is shared between the cxxbridge macro and the cmd.
2
3pub mod atom;
4mod attrs;
5pub mod check;
6mod doc;
7pub mod error;
8pub mod ident;
9mod impls;
10mod parse;
11pub mod set;
12mod tokens;
13pub mod types;
14
15use proc_macro2::Ident;
16use syn::{LitStr, Token};
17
18pub use self::atom::Atom;
19pub use self::doc::Doc;
20pub use self::parse::parse_items;
21pub use self::types::Types;
22
23pub enum Api {
24 Include(LitStr),
25 Struct(Struct),
26 CxxType(ExternType),
27 CxxFunction(ExternFn),
28 RustType(ExternType),
29 RustFunction(ExternFn),
30}
31
32pub struct ExternType {
33 pub doc: Doc,
34 pub type_token: Token![type],
35 pub ident: Ident,
36}
37
38pub struct Struct {
39 pub doc: Doc,
40 pub derives: Vec<Ident>,
41 pub struct_token: Token![struct],
42 pub ident: Ident,
43 pub fields: Vec<Var>,
44}
45
46pub struct ExternFn {
47 pub doc: Doc,
48 pub fn_token: Token![fn],
49 pub ident: Ident,
50 pub receiver: Option<Receiver>,
51 pub args: Vec<Var>,
52 pub ret: Option<Type>,
53 pub semi_token: Token![;],
54}
55
56pub struct Var {
57 pub ident: Ident,
58 pub ty: Type,
59}
60
61pub struct Receiver {
62 pub mutability: Option<Token![mut]>,
63 pub ident: Ident,
64}
65
66#[derive(Hash, Eq, PartialEq)]
67pub enum Type {
68 Ident(Ident),
69 RustBox(Box<Ty1>),
70 UniquePtr(Box<Ty1>),
71 Ref(Box<Ref>),
72 Str(Box<Ref>),
73}
74
75pub struct Ty1 {
76 pub name: Ident,
77 pub langle: Token![<],
78 pub inner: Type,
79 pub rangle: Token![>],
80}
81
82pub struct Ref {
83 pub ampersand: Token![&],
84 pub mutability: Option<Token![mut]>,
85 pub inner: Type,
86}
87
88#[derive(Copy, Clone, PartialEq)]
89pub enum Derive {
90 Clone,
91 Copy,
92}