irc_bot/util/
mod.rs

1use core::ErrorKind;
2use core::Result;
3use std::borrow::Cow;
4use std::panic;
5
6pub(crate) mod fmt;
7pub(crate) mod lock;
8pub mod regex;
9pub mod yaml;
10
11pub(crate) fn run_handler<S1, S2, F, R>(
12    feature_kind: S1,
13    feature_name: S2,
14    handler_invocation: F,
15) -> Result<R>
16where
17    S1: Into<Cow<'static, str>>,
18    S2: Into<Cow<'static, str>>,
19    F: FnOnce() -> R + panic::UnwindSafe,
20{
21    panic::catch_unwind(handler_invocation).map_err(|panic_payload| {
22        ErrorKind::HandlerPanic(feature_kind.into(), feature_name.into(), panic_payload).into()
23    })
24}