Skip to content

Commit 0666e3f

Browse files
authored
lib: add no-std error support (#478)
* feat: add no-std error support * refactor: reduce cfgs
1 parent f1b6cae commit 0666e3f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/error.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
//!
33
44
use alloc::string::String;
5+
use core::error;
56
use core::fmt;
67
use core::num::TryFromIntError;
78
use core::result;
8-
#[cfg(feature = "std")]
9-
use std::{error, io};
10-
119
#[non_exhaustive]
1210
#[derive(Debug)]
1311
/// A custom Goblin error
@@ -20,15 +18,15 @@ pub enum Error {
2018
Scroll(scroll::Error),
2119
/// An IO based error
2220
#[cfg(feature = "std")]
23-
IO(io::Error),
21+
IO(std::io::Error),
2422
/// Buffer is too short to hold N items
2523
BufferTooShort(usize, &'static str),
2624
}
2725

28-
#[cfg(feature = "std")]
2926
impl error::Error for Error {
3027
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
3128
match *self {
29+
#[cfg(feature = "std")]
3230
Error::IO(ref io) => Some(io),
3331
Error::Scroll(ref scroll) => Some(scroll),
3432
_ => None,
@@ -37,8 +35,8 @@ impl error::Error for Error {
3735
}
3836

3937
#[cfg(feature = "std")]
40-
impl From<io::Error> for Error {
41-
fn from(err: io::Error) -> Error {
38+
impl From<std::io::Error> for Error {
39+
fn from(err: std::io::Error) -> Error {
4240
Error::IO(err)
4341
}
4442
}

0 commit comments

Comments
 (0)