Skip to content

Commit caa784a

Browse files
authored
Merge pull request #127 from xyzzyz/amichalik/core-error
Implement core::error::Error for the error types
2 parents 873dcca + 740b29b commit caa784a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+139
-257
lines changed

etherparse/src/defrag/ip_defrag_error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl core::fmt::Display for IpDefragError {
4242
}
4343
}
4444

45-
impl std::error::Error for IpDefragError {}
45+
impl core::error::Error for IpDefragError {}
4646

4747
#[cfg(test)]
4848
mod tests {
@@ -100,7 +100,7 @@ mod tests {
100100

101101
#[test]
102102
fn source() {
103-
use std::error::Error;
103+
use core::error::Error;
104104
assert!(UnalignedFragmentPayloadLen {
105105
offset: IpFragOffset::try_new(0).unwrap(),
106106
payload_len: 16

etherparse/src/err/arp/arp_eth_ipv4_from_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ impl core::fmt::Display for ArpEthIpv4FromError {
3131
}
3232
}
3333

34-
#[cfg(feature = "std")]
35-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
36-
impl std::error::Error for ArpEthIpv4FromError {
37-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
34+
impl core::error::Error for ArpEthIpv4FromError {
35+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
3836
None
3937
}
4038
}

etherparse/src/err/arp/arp_hw_addr_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ impl core::fmt::Display for ArpHwAddrError {
2121
}
2222
}
2323

24-
#[cfg(feature = "std")]
25-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
26-
impl std::error::Error for ArpHwAddrError {
27-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
24+
impl core::error::Error for ArpHwAddrError {
25+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
2826
None
2927
}
3028
}

etherparse/src/err/arp/arp_new_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ impl core::fmt::Display for ArpNewError {
1919
}
2020
}
2121

22-
#[cfg(feature = "std")]
23-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
24-
impl std::error::Error for ArpNewError {
25-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
22+
impl core::error::Error for ArpNewError {
23+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
2624
None
2725
}
2826
}

etherparse/src/err/arp/arp_proto_addr_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ impl core::fmt::Display for ArpProtoAddrError {
2121
}
2222
}
2323

24-
#[cfg(feature = "std")]
25-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
26-
impl std::error::Error for ArpProtoAddrError {
27-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
24+
impl core::error::Error for ArpProtoAddrError {
25+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
2826
None
2927
}
3028
}

etherparse/src/err/from_slice_error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,8 @@ impl core::fmt::Display for FromSliceError {
112112
}
113113
}
114114

115-
#[cfg(feature = "std")]
116-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
117-
impl std::error::Error for FromSliceError {
118-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
115+
impl core::error::Error for FromSliceError {
116+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
119117
use FromSliceError::*;
120118
match self {
121119
Len(err) => Some(err),
@@ -333,7 +331,7 @@ mod tests {
333331
use super::{FromSliceError::*, *};
334332
use core::hash::{Hash, Hasher};
335333
use std::collections::hash_map::DefaultHasher;
336-
use std::error::Error;
334+
use core::error::Error;
337335
use std::format;
338336

339337
#[test]

etherparse/src/err/io/limited_read_error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ impl core::fmt::Display for LimitedReadError {
5353
}
5454
}
5555

56-
#[cfg(feature = "std")]
57-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
58-
impl std::error::Error for LimitedReadError {
59-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
56+
impl core::error::Error for LimitedReadError {
57+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
6058
use LimitedReadError::*;
6159
match self {
6260
Io(err) => Some(err),
@@ -106,7 +104,7 @@ mod test {
106104

107105
#[test]
108106
fn source() {
109-
use std::error::Error;
107+
use core::error::Error;
110108
assert!(Io(std::io::Error::new(
111109
std::io::ErrorKind::UnexpectedEof,
112110
"failed to fill whole buffer",

etherparse/src/err/ip/header_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ impl core::fmt::Display for HeaderError {
2727
}
2828
}
2929

30-
#[cfg(feature = "std")]
31-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
32-
impl std::error::Error for HeaderError {
33-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
30+
impl core::error::Error for HeaderError {
31+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
3432
use HeaderError::*;
3533
match self {
3634
UnsupportedIpVersion { version_number: _ } => None,

etherparse/src/err/ip/headers_error.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ impl core::fmt::Display for HeadersError {
2424
}
2525
}
2626

27-
#[cfg(feature = "std")]
28-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
29-
impl std::error::Error for HeadersError {
30-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
27+
impl core::error::Error for HeadersError {
28+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
3129
use HeadersError::*;
3230
match self {
3331
Ip(err) => Some(err),

etherparse/src/err/ip/headers_read_error.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,8 @@ impl core::fmt::Display for HeaderReadError {
6868
}
6969
}
7070

71-
#[cfg(feature = "std")]
72-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
73-
impl std::error::Error for HeaderReadError {
74-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
71+
impl core::error::Error for HeaderReadError {
72+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
7573
use HeaderReadError::*;
7674
match self {
7775
Io(err) => Some(err),
@@ -126,7 +124,7 @@ mod test {
126124

127125
#[test]
128126
fn source() {
129-
use std::error::Error;
127+
use core::error::Error;
130128
assert!(Io(std::io::Error::new(
131129
std::io::ErrorKind::UnexpectedEof,
132130
"failed to fill whole buffer",

0 commit comments

Comments
 (0)