indexbus_platform_core/
errors.rs1pub type Result<T> = core::result::Result<T, Error>;
5use core::fmt;
6
7#[derive(Debug)]
17pub enum Error {
18 Message(String),
20}
21
22impl Error {
23 pub fn msg(message: impl Into<String>) -> Self {
25 Self::Message(message.into())
26 }
27
28 pub(crate) fn panic_message(panic: Box<dyn core::any::Any + Send>) -> Self {
29 if let Some(s) = panic.downcast_ref::<&str>() {
30 return Self::msg(format!("thread panicked: {s}"));
31 }
32 if let Some(s) = panic.downcast_ref::<String>() {
33 return Self::msg(format!("thread panicked: {s}"));
34 }
35 Self::msg("thread panicked".to_string())
36 }
37}
38
39impl fmt::Display for Error {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 Error::Message(message) => write!(f, "{message}"),
43 }
44 }
45}
46
47#[cfg(feature = "std")]
48impl std::error::Error for Error {}