Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ std = ["deku_derive/std", "bitvec?/std", "alloc", "no_std_io/std"]
alloc = ["bitvec?/alloc"]
logging = ["deku_derive/logging", "log"]
no-assert-string = ["deku_derive/no-assert-string"]
error_in_core = []
bits = ["dep:bitvec", "deku_derive/bits"]

[dependencies]
Expand Down
22 changes: 19 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ impl core::fmt::Display for DekuError {
}
}

#[cfg(not(feature = "std"))]
impl core::error::Error for DekuError {}

#[cfg(not(feature = "std"))]
impl From<DekuError> for no_std_io::io::Error {
fn from(error: DekuError) -> Self {
use no_std_io::io;
match error {
DekuError::Incomplete(_) => io::Error::new(io::ErrorKind::UnexpectedEof, error),
DekuError::Parse(_) => io::Error::new(io::ErrorKind::InvalidData, error),
DekuError::InvalidParam(_) => io::Error::new(io::ErrorKind::InvalidInput, error),
DekuError::Assertion(_) => io::Error::new(io::ErrorKind::InvalidData, error),
DekuError::AssertionNoStr => io::Error::from(io::ErrorKind::InvalidData),
DekuError::IdVariantNotFound => io::Error::new(io::ErrorKind::NotFound, error),
DekuError::Io(e) => io::Error::new(e, error),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for DekuError {
fn cause(&self) -> Option<&dyn std::error::Error> {
Expand All @@ -112,6 +131,3 @@ impl From<DekuError> for std::io::Error {
}
}
}

#[cfg(feature = "error_in_core")]
impl core::error::Error for DekuError {}
Loading