-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathcomponent_bindings.rs
More file actions
269 lines (256 loc) · 10.7 KB
/
component_bindings.rs
File metadata and controls
269 lines (256 loc) · 10.7 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Generated by `wit-bindgen` 0.24.0. DO NOT EDIT!
// Options used:
#[allow(dead_code)]
pub mod example {
#[allow(dead_code)]
pub mod component {
#[allow(dead_code, clippy::all)]
pub mod cache {
#[used]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
static __FORCE_SECTION_REF: fn() =
super::super::super::__link_custom_section_describing_imports;
use super::super::super::_rt;
#[allow(unused_unsafe, clippy::all)]
/// Get a value from the cache.
pub fn get(key: &str) -> Option<_rt::Vec<u8>> {
unsafe {
#[repr(align(4))]
struct RetArea([::core::mem::MaybeUninit<u8>; 12]);
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 12]);
let vec0 = key;
let ptr0 = vec0.as_ptr().cast::<u8>();
let len0 = vec0.len();
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "example:component/cache")]
extern "C" {
#[link_name = "get"]
fn wit_import(_: *mut u8, _: usize, _: *mut u8);
}
#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: *mut u8, _: usize, _: *mut u8) {
unreachable!()
}
wit_import(ptr0.cast_mut(), len0, ptr1);
let l2 = i32::from(*ptr1.add(0).cast::<u8>());
match l2 {
0 => None,
1 => {
let e = {
let l3 = *ptr1.add(4).cast::<*mut u8>();
let l4 = *ptr1.add(8).cast::<usize>();
let len5 = l4;
_rt::Vec::from_raw_parts(l3.cast(), len5, len5)
};
Some(e)
}
_ => _rt::invalid_enum_discriminant(),
}
}
}
#[allow(unused_unsafe, clippy::all)]
/// Put a value into the cache.
pub fn put(key: &str, value: &[u8]) {
unsafe {
let vec0 = key;
let ptr0 = vec0.as_ptr().cast::<u8>();
let len0 = vec0.len();
let vec1 = value;
let ptr1 = vec1.as_ptr().cast::<u8>();
let len1 = vec1.len();
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "example:component/cache")]
extern "C" {
#[link_name = "put"]
fn wit_import(_: *mut u8, _: usize, _: *mut u8, _: usize);
}
#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: *mut u8, _: usize, _: *mut u8, _: usize) {
unreachable!()
}
wit_import(ptr0.cast_mut(), len0, ptr1.cast_mut(), len1);
}
}
}
#[allow(dead_code, clippy::all)]
pub mod backend {
#[used]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
static __FORCE_SECTION_REF: fn() =
super::super::super::__link_custom_section_describing_imports;
use super::super::super::_rt;
#[allow(unused_unsafe, clippy::all)]
/// Fetch the content bytes of the given URL.
pub fn fetch(url: &str) -> _rt::Vec<u8> {
unsafe {
#[repr(align(4))]
struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
let vec0 = url;
let ptr0 = vec0.as_ptr().cast::<u8>();
let len0 = vec0.len();
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
#[cfg(target_arch = "wasm32")]
#[link(wasm_import_module = "example:component/backend")]
extern "C" {
#[link_name = "fetch"]
fn wit_import(_: *mut u8, _: usize, _: *mut u8);
}
#[cfg(not(target_arch = "wasm32"))]
fn wit_import(_: *mut u8, _: usize, _: *mut u8) {
unreachable!()
}
wit_import(ptr0.cast_mut(), len0, ptr1);
let l2 = *ptr1.add(0).cast::<*mut u8>();
let l3 = *ptr1.add(4).cast::<usize>();
let len4 = l3;
_rt::Vec::from_raw_parts(l2.cast(), len4, len4)
}
}
}
}
}
#[allow(dead_code)]
pub mod exports {
#[allow(dead_code)]
pub mod example {
#[allow(dead_code)]
pub mod component {
#[allow(dead_code, clippy::all)]
pub mod backend {
#[used]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
static __FORCE_SECTION_REF: fn() =
super::super::super::super::__link_custom_section_describing_imports;
use super::super::super::super::_rt;
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn _export_fetch_cabi<T: Guest>(arg0: *mut u8, arg1: usize) -> *mut u8 {
#[cfg(target_arch = "wasm32")]
_rt::run_ctors_once();
let len0 = arg1;
let bytes0 = _rt::Vec::from_raw_parts(arg0.cast(), len0, len0);
let result1 = T::fetch(_rt::string_lift(bytes0));
let ptr2 = _RET_AREA.0.as_mut_ptr().cast::<u8>();
let vec3 = (result1).into_boxed_slice();
let ptr3 = vec3.as_ptr().cast::<u8>();
let len3 = vec3.len();
::core::mem::forget(vec3);
*ptr2.add(4).cast::<usize>() = len3;
*ptr2.add(0).cast::<*mut u8>() = ptr3.cast_mut();
ptr2
}
#[doc(hidden)]
#[allow(non_snake_case)]
pub unsafe fn __post_return_fetch<T: Guest>(arg0: *mut u8) {
let l0 = *arg0.add(0).cast::<*mut u8>();
let l1 = *arg0.add(4).cast::<usize>();
let base2 = l0;
let len2 = l1;
_rt::cabi_dealloc(base2, len2 * 1, 1);
}
pub trait Guest {
/// Fetch the content bytes of the given URL.
fn fetch(url: _rt::String) -> _rt::Vec<u8>;
}
#[doc(hidden)]
macro_rules! __export_example_component_backend_cabi{
($ty:ident with_types_in $($path_to_types:tt)*) => (const _: () = {
#[export_name = "example:component/backend#fetch"]
unsafe extern "C" fn export_fetch(arg0: *mut u8,arg1: usize,) -> *mut u8 {
$($path_to_types)*::_export_fetch_cabi::<$ty>(arg0, arg1)
}
#[export_name = "cabi_post_example:component/backend#fetch"]
unsafe extern "C" fn _post_return_fetch(arg0: *mut u8,) {
$($path_to_types)*::__post_return_fetch::<$ty>(arg0)
}
};);
}
#[doc(hidden)]
pub(crate) use __export_example_component_backend_cabi;
#[repr(align(4))]
struct _RetArea([::core::mem::MaybeUninit<u8>; 8]);
static mut _RET_AREA: _RetArea = _RetArea([::core::mem::MaybeUninit::uninit(); 8]);
}
}
}
}
mod _rt {
pub use alloc_crate::vec::Vec;
pub unsafe fn invalid_enum_discriminant<T>() -> T {
if cfg!(debug_assertions) {
panic!("invalid enum discriminant")
} else {
core::hint::unreachable_unchecked()
}
}
#[cfg(target_arch = "wasm32")]
pub fn run_ctors_once() {
wit_bindgen_rt::run_ctors_once();
}
pub unsafe fn string_lift(bytes: Vec<u8>) -> String {
if cfg!(debug_assertions) {
String::from_utf8(bytes).unwrap()
} else {
String::from_utf8_unchecked(bytes)
}
}
pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) {
if size == 0 {
return;
}
let layout = alloc::Layout::from_size_align_unchecked(size, align);
alloc::dealloc(ptr as *mut u8, layout);
}
pub use alloc_crate::string::String;
extern crate alloc as alloc_crate;
pub use alloc_crate::alloc;
}
/// Generates `#[no_mangle]` functions to export the specified type as the
/// root implementation of all generated traits.
///
/// For more information see the documentation of `wit_bindgen::generate!`.
///
/// ```rust
/// # macro_rules! export{ ($($t:tt)*) => (); }
/// # trait Guest {}
/// struct MyType;
///
/// impl Guest for MyType {
/// // ...
/// }
///
/// export!(MyType);
/// ```
#[allow(unused_macros)]
#[doc(hidden)]
macro_rules! __export_example_impl {
($ty:ident) => (self::export!($ty with_types_in self););
($ty:ident with_types_in $($path_to_types_root:tt)*) => (
$($path_to_types_root)*::exports::example::component::backend::__export_example_component_backend_cabi!($ty with_types_in $($path_to_types_root)*::exports::example::component::backend);
)
}
#[doc(inline)]
pub(crate) use __export_example_impl as export;
#[cfg(target_arch = "wasm32")]
#[link_section = "component-type:wit-bindgen:0.24.0:example:encoded world"]
#[doc(hidden)]
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 354] = *b"\
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xe4\x01\x01A\x02\x01\
A\x06\x01B\x06\x01p}\x01k\0\x01@\x01\x03keys\0\x01\x04\0\x03get\x01\x02\x01@\x02\
\x03keys\x05value\0\x01\0\x04\0\x03put\x01\x03\x03\x01\x17example:component/cach\
e\x05\0\x01B\x03\x01p}\x01@\x01\x03urls\0\0\x04\0\x05fetch\x01\x01\x03\x01\x19ex\
ample:component/backend\x05\x01\x01B\x03\x01p}\x01@\x01\x03urls\0\0\x04\0\x05fet\
ch\x01\x01\x04\x01\x19example:component/backend\x05\x02\x04\x01\x19example:compo\
nent/example\x04\0\x0b\x0d\x01\0\x07example\x03\0\0\0G\x09producers\x01\x0cproce\
ssed-by\x02\x0dwit-component\x070.202.0\x10wit-bindgen-rust\x060.24.0";
#[inline(never)]
#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
pub fn __link_custom_section_describing_imports() {
wit_bindgen_rt::maybe_link_cabi_realloc();
}