rfham_core/error.rs
1//!
2//! Provides this crate's [`Error`] and [`Result`] types.
3//!
4
5use thiserror::Error;
6
7#[cfg(feature = "std")]
8use std::io::Error as IoError;
9
10#[cfg(feature = "std")]
11use std::string::FromUtf8Error;
12
13#[cfg(not(feature = "std"))]
14use alloc::string::FromUtf8Error;
15
16// ------------------------------------------------------------------------------------------------
17// Public Types
18// ------------------------------------------------------------------------------------------------
19
20///
21/// The `Error` type for this crate.
22///
23#[derive(Debug, Error)]
24pub enum CoreError {
25 #[error("Unable to parse string as `{1}`; value: {0:?}")]
26 InvalidValueFromStr(String, &'static str),
27
28 #[error("Value `{0}` is not valid for type `{1}`")]
29 InvalidValue(String, &'static str),
30
31 #[error("Unable to convert from UTF-8 to string; error: {0}")]
32 FromUtf(#[from] FromUtf8Error),
33
34 #[cfg(feature = "std")]
35 #[error("An I/O error occurred; error: {0}")]
36 Io(#[from] IoError),
37}
38
39///
40/// A `Result` type that specifically uses this crate's `Error`.
41///
42pub type Result<T> = std::result::Result<T, CoreError>;