blob: 1e56780e769b71fc691b1b0a96e24f8f49d9c278 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
use alloc::string::String;
use core::{fmt, result};
#[cfg(feature = "std")]
use std::error;
use crate::{read, write};
/// The error type used within the build module.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Error(pub(super) String);
impl Error {
pub(super) fn new(message: impl Into<String>) -> Self {
Error(message.into())
}
}
impl fmt::Display for Error {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[cfg(feature = "std")]
impl error::Error for Error {}
#[cfg(all(not(feature = "std"), core_error))]
impl core::error::Error for Error {}
impl From<read::Error> for Error {
fn from(error: read::Error) -> Error {
Error(format!("{}", error))
}
}
impl From<write::Error> for Error {
fn from(error: write::Error) -> Error {
Error(error.0)
}
}
/// The result type used within the build module.
pub type Result<T> = result::Result<T, Error>;
|