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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//! Services and mod events: their specs and layouts.
use c_void;
use crate;
/// One field of a service table or mod event, as its layout hash sees it.
///
/// Frozen: written as an array.
///
/// # Examples
///
/// ```
/// use enshwick::abi::{LayoutField, Str};
///
/// let field = LayoutField { name: Str::new("price"), hash: 7 };
/// assert_eq!(field.hash, 7);
/// ```
/// The layout of a service table or mod event, field by field.
///
/// # Examples
///
/// ```
/// use enshwick::abi::Layout;
///
/// let layout = Layout { fields: core::ptr::null(), count: 0, size: 0 };
/// assert_eq!(layout.count, 0);
/// ```
/// A service a mod publishes, or the one it asks for.
///
/// # Examples
///
/// ```
/// use enshwick::abi::{Header, Layout, ServiceSpec, Str};
///
/// let spec = ServiceSpec {
/// header: Header::of::<ServiceSpec>(),
/// name: Str::new("you.trading-post:prices"),
/// major: 1,
/// layout: Layout { fields: core::ptr::null(), count: 0, size: 0 },
/// table: core::ptr::null(),
/// };
/// assert_eq!(spec.major, 1);
/// ```
impl_headed!;
/// What [`HostApi::service`](super::HostApi::service) found.
///
/// # Examples
///
/// ```
/// use enshwick::abi::ServiceFound;
///
/// let found = ServiceFound::EMPTY;
/// assert!(found.table.is_null());
/// ```
impl_headed!;
/// A mod event a mod defines, or the one it subscribes to.
///
/// # Examples
///
/// ```
/// use enshwick::abi::{EventSpec, Header, Layout, Str};
///
/// let spec = EventSpec {
/// header: Header::of::<EventSpec>(),
/// name: Str::new("you.trading-post:sold"),
/// layout: Layout { fields: core::ptr::null(), count: 0, size: 0 },
/// };
/// assert_eq!(spec.layout.size, 0);
/// ```
impl_headed!;
/// A mod's handler for a mod event: the event's data, valid for the call,
/// and the pointer given at subscription.
pub type ModEventFn = unsafe extern "system" fn;
/// A described service, a call: one function from an input struct to an
/// answer, which one mod serves and others call, or the call a mod asks for.
///
/// # Examples
///
/// ```
/// use enshwick::abi::{CallSpec, Header, Layout, Str};
///
/// let none = Layout { fields: core::ptr::null(), count: 0, size: 0 };
/// let spec = CallSpec {
/// header: Header::of::<CallSpec>(),
/// name: Str::new("you.trading-post:price-of"),
/// major: 1,
/// input: none,
/// output: none,
/// };
/// assert_eq!(spec.major, 1);
/// ```
impl_headed!;
/// A mod's handler for a call it serves.
///
/// It gets the input, valid for the call, the answer to write, as large as
/// the spec's output, and the pointer given at serving, and answers
/// [`Status::OK`](super::Status::OK) only once the whole answer is written.
/// It runs on the caller's thread, any thread, possibly on several at once
/// and inside another call, and must not unwind.
pub type CallFn = unsafe extern "system" fn ;