Skip to main content

aidoku/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[cfg(feature = "helpers")]
5pub mod helpers;
6
7#[cfg(feature = "imports")]
8pub mod imports;
9
10#[cfg(feature = "imports")]
11mod macros;
12
13mod structs;
14
15pub use structs::*;
16
17// talc allocator
18#[cfg(target_family = "wasm")]
19#[cfg(feature = "talc")]
20#[global_allocator]
21static ALLOCATOR: talc::TalckWasm = unsafe { talc::TalckWasm::new_global() };
22
23// panic handler
24#[cfg(target_family = "wasm")]
25#[cfg(not(feature = "test"))]
26#[panic_handler]
27fn panic(info: &core::panic::PanicInfo) -> ! {
28	#[link(wasm_import_module = "std")]
29	unsafe extern "C" {
30		fn abort();
31		fn print(string: *const u8, size: usize);
32	}
33
34	let message = prelude::format!("{}", info);
35	unsafe {
36		// print the error message to aidoku logs
37		print(message.as_ptr(), message.len());
38		// tell aidoku we're aborting so that the unreachable instruction is not executed
39		abort();
40	};
41
42	core::arch::wasm32::unreachable()
43}
44
45// re-export dependencies for `register_source` macro to access
46pub use postcard;
47pub use serde;
48
49/// Re-export of `alloc` crate.
50pub mod alloc {
51	#![allow(hidden_glob_reexports)]
52	extern crate alloc;
53	pub use alloc::*;
54
55	pub use alloc::boxed::Box;
56	pub use alloc::string::String;
57	pub use alloc::vec::Vec;
58}
59
60/// The prelude macros.
61pub mod prelude {
62	pub use super::alloc::format;
63	#[cfg(feature = "imports")]
64	pub use crate::{bail, debug, error, println, register_source};
65}