#[cfg(target_arch = "wasm32")]
#[cfg(feature = "oom-handler")]
#[alloc_error_handler]
pub fn oom(_: core::alloc::Layout) -> ! {
crate::ext::oom_panic()
}
#[cfg(target_arch = "wasm32")]
#[cfg(feature = "panic-handler")]
mod panic_handler {
use crate::ext;
use core::panic::PanicInfo;
mod constants {
pub const PANIC_PREFIX: &str = "panicked with ";
#[cfg(not(feature = "panic-message"))]
pub const UNKNOWN_REASON: &str = "<unknown>";
#[cfg(feature = "panic-message")]
pub const TRIMMED_MAX_LEN: usize = 1024; }
use constants::*;
#[cfg(not(feature = "panic-message"))]
#[panic_handler]
pub fn panic(_: &PanicInfo) -> ! {
const MESSAGE: &str = const_format::formatcp!("{PANIC_PREFIX}'{UNKNOWN_REASON}'");
#[cfg(feature = "debug")]
ext::debug(MESSAGE);
ext::panic_str(MESSAGE)
}
#[cfg(feature = "panic-message")]
#[panic_handler]
pub fn panic(panic_info: &PanicInfo) -> ! {
use crate::prelude::fmt::Write;
use arrayvec::ArrayString;
let mut debug_msg = ArrayString::<TRIMMED_MAX_LEN>::new();
let _ = debug_msg.try_push_str(PANIC_PREFIX);
let msg = panic_info.message();
#[cfg(feature = "panic-location")]
if let Some(loc) = panic_info.location() {
let _ = write!(&mut debug_msg, "'{msg}' at '{loc}'");
}
#[cfg(not(feature = "panic-location"))]
let _ = write!(&mut debug_msg, "'{msg}'");
#[cfg(feature = "debug")]
ext::debug(&debug_msg);
ext::panic_str(&debug_msg)
}
}