Skip to content

Commit 92d0e0c

Browse files
Soften requirement on 'std' to 'alloc' now that 'Error' is 'core' instead of 'std'. (#726)
1 parent 4bed9d6 commit 92d0e0c

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

slice-codec/src/buffer/vec.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,7 @@ impl<'a> VecOutputTarget<'a> {
3333
// If an error occurred, we wrap it in our own `UnexpectedEob` error and return it.
3434
let remaining = self.remaining();
3535
let kind = ErrorKind::UnexpectedEob { requested, remaining };
36-
37-
// Remove this feature gate when the `Error` trait is moved; https://github.com/icerpc/slice-rust/issues/1.
38-
#[cfg(feature = "std")]
39-
return Error::new_with_source(kind, _err);
40-
#[cfg(not(feature = "std"))]
41-
return Error::new(kind);
36+
Error::new_with_source(kind, _err)
4237
})
4338
}
4439
}

slice-codec/src/error.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ use core::num::TryFromIntError;
55
use core::ops::Range;
66
use core::write;
77

8+
#[cfg(feature = "alloc")]
9+
use alloc::boxed::Box;
810
#[cfg(feature = "alloc")]
911
use alloc::collections::TryReserveError;
1012
#[cfg(feature = "alloc")]
1113
use alloc::string::FromUtf8Error;
1214

13-
#[cfg(feature = "std")]
14-
use alloc::boxed::Box;
15-
1615
/// A specialized [`Result`](core::result::Result) type for encoding and decoding functions which may produce errors.
1716
///
1817
/// This typedef is a convenience to avoid repetitively specifying [`Error`] as the error type, and is a direct mapping
@@ -26,25 +25,23 @@ pub struct Error {
2625
kind: ErrorKind,
2726

2827
/// The underlying cause of this error, if any exist.
29-
// Until `Error` is moved from `std` into `core`, we need a feature; https://github.com/icerpc/slice-rust/issues/1.
30-
#[cfg(feature = "std")]
31-
source: Option<Box<dyn std::error::Error + 'static>>,
28+
#[cfg(feature = "alloc")]
29+
source: Option<Box<dyn core::error::Error + 'static>>,
3230
}
3331

3432
impl Error {
3533
/// Creates a new error of the specified kind, with no underlying source.
3634
pub fn new(kind: ErrorKind) -> Self {
3735
Self {
3836
kind,
39-
#[cfg(feature = "std")]
37+
#[cfg(feature = "alloc")]
4038
source: None,
4139
}
4240
}
4341

4442
/// Creates a new error of the specified kind, which was logically caused by the provided source.
45-
// Until `Error` is moved from `std` into `core`, we need a feature; https://github.com/icerpc/slice-rust/issues/1.
46-
#[cfg(feature = "std")]
47-
pub fn new_with_source(kind: ErrorKind, source: impl std::error::Error + 'static) -> Self {
43+
#[cfg(feature = "alloc")]
44+
pub fn new_with_source(kind: ErrorKind, source: impl core::error::Error + 'static) -> Self {
4845
Self {
4946
kind,
5047
source: Some(Box::new(source)),
@@ -62,8 +59,7 @@ impl Display for Error {
6259
// Write this error's underlying `ErrorKind`.
6360
self.kind.fmt(f)?;
6461

65-
// Until `Error` is moved from `std` into `core`, we need a feature; https://github.com/icerpc/slice-rust/issues/1.
66-
#[cfg(feature = "std")]
62+
#[cfg(feature = "alloc")]
6763
// If this error was caused by another error, also write that source error.
6864
if let Some(source) = &self.source {
6965
f.write_str("\nError was caused by:\n")?;
@@ -74,10 +70,9 @@ impl Display for Error {
7470
}
7571
}
7672

77-
// Until `Error` is moved from `std` into `core`, we need a feature; https://github.com/icerpc/slice-rust/issues/1.
78-
#[cfg(feature = "std")]
79-
impl std::error::Error for Error {
80-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
73+
#[cfg(feature = "alloc")]
74+
impl core::error::Error for Error {
75+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
8176
self.source.as_deref()
8277
}
8378
}

0 commit comments

Comments
 (0)