Skip to content

Commit 02eb077

Browse files
authored
der: bound Decode(Value)::Error on core::error::Error (#2137)
Now that the `Error` trait is always available in `core`, we can use it as a bound for associated error types, which makes them more convenient to use in generic code.
1 parent 23b3622 commit 02eb077

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

der/src/decode.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::EncodingRules;
5454
)]
5555
pub trait Decode<'a>: Sized + 'a {
5656
/// Type returned in the event of a decoding error.
57-
type Error: From<Error> + 'static;
57+
type Error: core::error::Error + From<Error> + 'static;
5858

5959
/// Attempt to decode this TLV message using the provided decoder.
6060
fn decode<R: Reader<'a>>(decoder: &mut R) -> Result<Self, Self::Error>;
@@ -193,7 +193,7 @@ impl<T: DecodeOwned<Error = Error> + PemLabel> DecodePem for T {
193193
/// ```
194194
pub trait DecodeValue<'a>: Sized {
195195
/// Type returned in the event of a decoding error.
196-
type Error: From<Error> + 'static;
196+
type Error: core::error::Error + From<Error> + 'static;
197197

198198
/// Attempt to decode this value using the provided [`Reader`].
199199
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self, Self::Error>;
@@ -217,7 +217,7 @@ where
217217
T: ToOwned + ?Sized,
218218
&'a T: DecodeValue<'a, Error = E>,
219219
T::Owned: for<'b> DecodeValue<'b, Error = E>,
220-
E: From<Error> + 'static,
220+
E: core::error::Error + From<Error> + 'static,
221221
{
222222
type Error = E;
223223

der/tests/derive.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@
1515
#[allow(dead_code)]
1616
pub struct CustomError(der::Error);
1717

18+
impl core::error::Error for CustomError {}
19+
20+
impl core::fmt::Display for CustomError {
21+
fn fmt(&self, _: &mut core::fmt::Formatter) -> core::fmt::Result {
22+
unimplemented!()
23+
}
24+
}
25+
1826
impl From<der::Error> for CustomError {
1927
fn from(value: der::Error) -> Self {
2028
Self(value)
2129
}
2230
}
2331

24-
impl From<std::convert::Infallible> for CustomError {
32+
impl From<core::convert::Infallible> for CustomError {
2533
fn from(_value: std::convert::Infallible) -> Self {
2634
unreachable!()
2735
}

0 commit comments

Comments
 (0)