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	unsafe extern "C" {
29		fn abort();
30		fn print(string: *const u8, size: usize);
31	}
32
33	let message = prelude::format!("{}", info);
34	unsafe {
35		// print the error message to aidoku logs
36		print(message.as_ptr(), message.len());
37		// tell aidoku we're aborting so that the unreachable instruction is not executed
38		abort();
39	};
40
41	core::arch::wasm32::unreachable()
42}
43
44// re-export dependencies for `register_source` macro to access
45pub use postcard;
46pub use serde;
47
48/// Re-export of `alloc` crate.
49pub mod alloc {
50	#![allow(hidden_glob_reexports)]
51	extern crate alloc;
52	pub use alloc::*;
53
54	pub use alloc::boxed::Box;
55	pub use alloc::string::String;
56	pub use alloc::vec::Vec;
57}
58
59/// The prelude macros.
60pub mod prelude {
61	pub use super::alloc::format;
62	#[cfg(feature = "imports")]
63	pub use crate::{bail, debug, error, println, register_source};
64}