1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/// Registers an additional type with the inventory.
///
/// Use this for types that are not already pulled in transitively through a function
/// or service signature but still need to appear in the generated bindings.
///
/// ```rust
/// # use interoptopus::{ffi, extra_type};
/// # use interoptopus::inventory::RustInventory;
/// #[ffi]
/// pub struct Extra { pub count: u32 }
///
/// pub fn ffi_inventory() -> RustInventory {
/// RustInventory::new()
/// .register(extra_type!(Extra))
/// .validate()
/// }
/// ```
/// Registers a function with the inventory.
///
/// The argument is the function's path (the `#[ffi]` attribute generates a companion
/// type that implements [`FunctionInfo`](crate::lang::function::FunctionInfo)).
/// All parameter and return types are registered automatically.
///
/// ```rust
/// # use interoptopus::{ffi, function};
/// # use interoptopus::inventory::RustInventory;
/// #[ffi]
/// pub fn my_add(a: u32, b: u32) -> u32 { a + b }
///
/// pub fn ffi_inventory() -> RustInventory {
/// RustInventory::new()
/// .register(function!(my_add))
/// .validate()
/// }
/// ```
/// Registers a constant with the inventory.
///
/// The argument is the constant's path (the `#[ffi]` attribute generates a companion
/// type that implements [`ConstantInfo`](crate::lang::constant::ConstantInfo)).
///
/// ```rust
/// # use interoptopus::{ffi, constant};
/// # use interoptopus::inventory::RustInventory;
/// #[ffi]
/// pub const MAX_ITEMS: u32 = 1024;
///
/// pub fn ffi_inventory() -> RustInventory {
/// RustInventory::new()
/// .register(constant!(MAX_ITEMS))
/// .validate()
/// }
/// ```
/// Registers a service with the inventory.
///
/// The argument is the service struct's path. The struct must have both `#[ffi(service)]`
/// on the struct and `#[ffi]` on its `impl` block. All methods and their types are
/// registered automatically.
///
/// ```rust
/// # use interoptopus::{ffi, service};
/// # use interoptopus::inventory::RustInventory;
/// #[ffi]
/// pub enum MyError { General }
///
/// #[ffi(service)]
/// pub struct MyService { count: u32 }
///
/// #[ffi]
/// impl MyService {
/// pub fn create() -> ffi::Result<Self, MyError> { ffi::Ok(Self { count: 0 }) }
/// pub fn fetch(&self) -> u32 { self.count }
/// }
///
/// pub fn ffi_inventory() -> RustInventory {
/// RustInventory::new()
/// .register(service!(MyService))
/// .validate()
/// }
/// ```