shadow_rs/
err.rs

1use std::error::Error;
2use std::error::Error as StdError;
3use std::fmt::{Display, Formatter};
4use std::string::FromUtf8Error;
5
6/// Results returned by the `shadow-rs` build process.
7/// For more information see [`ShadowError`].
8pub type SdResult<T> = Result<T, ShadowError>;
9
10/// `shadow-rs` build process errors.
11/// This type wraps multiple kinds of underlying errors that can occur downstream of `shadow-rs`, such as [`std::io::Error`].
12#[derive(Debug)]
13pub enum ShadowError {
14    String(String),
15}
16
17impl ShadowError {
18    pub fn new(err: impl Error) -> Self {
19        ShadowError::String(err.to_string())
20    }
21}
22
23impl From<std::string::FromUtf8Error> for ShadowError {
24    fn from(e: FromUtf8Error) -> Self {
25        ShadowError::String(e.to_string())
26    }
27}
28
29impl From<std::io::Error> for ShadowError {
30    fn from(e: std::io::Error) -> Self {
31        ShadowError::String(e.to_string())
32    }
33}
34
35impl From<String> for ShadowError {
36    fn from(e: String) -> Self {
37        ShadowError::String(e)
38    }
39}
40
41impl From<&str> for ShadowError {
42    fn from(e: &str) -> Self {
43        ShadowError::String(e.to_string())
44    }
45}
46
47impl From<std::env::VarError> for ShadowError {
48    fn from(e: std::env::VarError) -> Self {
49        ShadowError::String(e.to_string())
50    }
51}
52
53impl From<std::num::ParseIntError> for ShadowError {
54    fn from(e: std::num::ParseIntError) -> Self {
55        ShadowError::String(e.to_string())
56    }
57}
58
59impl Display for ShadowError {
60    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
61        match self {
62            ShadowError::String(err) => f.write_str(err),
63        }
64    }
65}
66
67impl StdError for ShadowError {}