browser_panic_hook/mode/
custom_body.rs1use crate::mode::{PanicDetails, PresentationMode};
2use std::borrow::Cow;
3
4pub struct CustomBody(pub Box<dyn Fn(PanicDetails) -> String + 'static + Send + Sync>);
9
10impl<F> From<F> for CustomBody
11where
12 F: for<'a> Fn(PanicDetails<'a>) -> String + 'static + Send + Sync,
13{
14 fn from(value: F) -> Self {
15 Self(Box::new(value))
16 }
17}
18
19impl PresentationMode for CustomBody {
20 fn present(&self, details: PanicDetails) -> Result<(), Cow<'static, str>> {
21 super::set_body(None, self.0(details))
22 }
23}