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
//! A C ABI over the crate, for callers outside Rust.
//!
//! Every symbol here is `extern "C"` and prefixed `soyokaze_`, and the shared
//! library the crate builds as (`libsoyokaze.so`, `libsoyokaze.dylib`,
//! `soyokaze.dll`) exports exactly this surface. The C declarations live in
//! `include/soyokaze.h`.
//!
//! # Layout
//!
//! The modules mirror the crate they wrap: [`errors`] carries [`Error`] across
//! the boundary, [`models`] carries [`Url`] and [`Message`], and [`client`] and
//! [`server`] are the two entry points. What every module shares lives here —
//! the [`Slice`] and [`Buffer`] octet views, and the [`Runtime`] that turns the
//! crate's async surface into blocking calls.
//!
//! [`Error`]: crate::errors::Error
//! [`Url`]: crate::models::Url
//! [`Message`]: crate::models::Message
//!
//! # Conventions
//!
//! - A fallible call returns a [`Status`] and writes its result through an out
//! parameter. Passing a non-null `error` out parameter takes ownership of an
//! [`Error`] handle describing the failure, which the caller frees with
//! `soyokaze_error_free`.
//! - Text and octets go in as a pointer and a length, never as a NUL-terminated
//! string, so a value may hold a NUL and need not be copied to be passed.
//! - Text and octets come back either as a [`Slice`], borrowed from a handle and
//! valid until that handle is freed or modified, or as a [`Buffer`], owned by
//! the caller and freed with `soyokaze_buffer_free`.
//! - A handle is freed exactly once, with the `_free` call that matches the
//! `_new`, `_parse` or `_request` call that produced it. A call documented as
//! consuming a handle frees it itself, and the caller must not.
//! - A null handle is treated as absent wherever that is meaningful, and is
//! never dereferenced.
pub use Status;
/// A borrowed view of octets.
///
/// Points into whichever handle produced it and stays valid until that handle
/// is freed or modified. A `data` of null means the value was absent, which is
/// how a lookup that found nothing is told apart from one that found an empty
/// value.
/// Octets owned by the caller.
///
/// Freed with [`soyokaze_buffer_free`]. `capacity` is what the allocation was
/// made with and has to be handed back untouched for the memory to be released.
/// Releases a [`Buffer`].
///
/// A buffer that was already freed, or that never held anything, must not be
/// passed twice; an empty buffer is safe to pass.
///
/// # Safety
///
/// `buffer` must be one this library produced and has not yet been freed.
pub unsafe extern "C"
/// The crate's version, as `MAJOR.MINOR.PATCH`.
pub extern "C"
/// Borrows `len` octets from `data`.
///
/// A null `data` borrows nothing, which is how an absent argument is passed.
///
/// # Safety
///
/// `data` must either be null or point to `len` readable octets that outlive
/// the returned slice.
pub unsafe
/// Borrows `len` octets from `data` as UTF-8.
///
/// Returns `None` when the argument is absent or is not UTF-8, which callers
/// report as [`Status::Invalid`].
///
/// # Safety
///
/// As [`borrow`].
pub unsafe
/// The runtime the blocking calls in this module drive.
///
/// The crate's own surface is async; every FFI call that has to wait runs on
/// one of these. It is multi-threaded, so work a call leaves running — the
/// accept loops [`server::soyokaze_server_serve`] starts, most of all — keeps
/// running after that call returns.
;
/// Builds a [`Runtime`] with `workers` threads, or one thread per core when
/// `workers` is zero.
///
/// Returns null when the runtime cannot be built.
pub extern "C"
/// Releases a [`Runtime`], waiting for the work still on it to finish.
///
/// # Safety
///
/// `runtime` must come from [`soyokaze_runtime_new`] and not have been freed.
pub unsafe extern "C"