1use cfg_if::cfg_if;
2
3cfg_if! {
4 if #[cfg(target_os = "android")] {
5 mod android;
6 pub use android::*;
7 } else if #[cfg(target_os = "ios")] {
8 mod iphone;
9 pub use iphone::*;
10 } else if #[cfg(target_os = "macos")] {
11 mod macos;
12 pub use macos::*;
13 } else if #[cfg(any(unix, target_os = "redox"))] {
14 mod linux;
15 pub use linux::*;
16 } else if #[cfg(target_os = "windows")] {
17 mod windows;
18 pub use windows::*;
19 } else if #[cfg(target_os = "wasi")] {
20 mod wasi;
21 pub use wasi::*;
22 compile_error!("Unsupported target OS! wasi-libc can not supported yet. Create an issue: https://github.com/nziq53/nickname/issues/new");
23 } else {
24 compile_error!("Unsupported target OS! Create an issue: https://github.com/nziq53/nickname/issues/new");
25 }
26}
27
28use std::{result, time::Duration};
29
30pub type Result<T> = result::Result<T, Error>;
31
32#[derive(Debug, thiserror::Error)]
33pub enum Error {
34 #[error("Permission denied")]
35 PermissionDenied,
36
37 #[error("BluetoothAdapter is null. Maybe bluetooth feature is not supported")]
38 BluetoothAdapterNull,
39
40 #[error("API level is too low. Required API level is 5 or higher")]
41 ApiLevelTooLow,
42
43 #[error("The operation is not supported: {}", _0)]
44 NotSupported(String),
45
46 #[error("Timed out after {:?}", _0)]
47 TimedOut(Duration),
48
49 #[error("Runtime Error: {}", _0)]
50 RuntimeError(String),
51
52 #[error("{}", _0)]
53 Other(Box<dyn std::error::Error + Send + Sync>),
54}
55
56impl From<std::io::Error> for Error {
57 fn from(val: std::io::Error) -> Self {
58 match val.kind() {
59 std::io::ErrorKind::PermissionDenied => Error::PermissionDenied,
60 _ => Error::Other(Box::new(val)),
61 }
62 }
63}