Skip to main content

rfham_core/
error.rs

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