use core::fmt::{self, Write};
const BUF_LEN: usize = 512;
struct FixedWriter {
buf: [u8; BUF_LEN],
len: usize,
}
impl FixedWriter {
const fn new() -> Self {
Self {
buf: [0; BUF_LEN],
len: 0,
}
}
fn as_str(&self) -> &str {
core::str::from_utf8(&self.buf[..self.len]).unwrap_or("")
}
}
impl Write for FixedWriter {
fn write_str(&mut self, s: &str) -> fmt::Result {
for c in s.chars() {
let need = c.len_utf8();
if self.len + need > BUF_LEN {
return Ok(()); }
c.encode_utf8(&mut self.buf[self.len..]);
self.len += need;
}
Ok(())
}
}
pub fn report_panic(info: &core::panic::PanicInfo) -> ! {
let mut w = FixedWriter::new();
let _ = write!(w, "[rust panic] {info}");
crate::wc_log(w.as_str());
#[cfg(target_arch = "wasm32")]
core::arch::wasm32::unreachable();
#[cfg(not(target_arch = "wasm32"))]
loop {
core::hint::spin_loop();
}
}