1use std::fmt::Display;
3
4#[derive(Debug)]
6pub enum Error {
7 Unsupported,
9 Unavailable,
11 MainThreadRequired,
13 Platform(Box<dyn std::error::Error + Send + Sync>),
15}
16
17impl Display for Error {
18 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19 match self {
20 Error::Unsupported => write!(f, "Unsupported operation"),
21 Error::Unavailable => write!(f, "Unavailable data"),
22 Error::MainThreadRequired => write!(f, "Main thread required"),
23 Error::Platform(err) => write!(f, "Platform error: {}", err),
24 }
25 }
26}
27
28impl std::error::Error for Error {}
29
30impl Error {
31 pub fn from_platform(err: impl std::error::Error + Send + Sync + 'static) -> Self {
33 Error::Platform(Box::new(err))
34 }
35}