@@ -5,14 +5,13 @@ use core::num::TryFromIntError;
55use core:: ops:: Range ;
66use core:: write;
77
8+ #[ cfg( feature = "alloc" ) ]
9+ use alloc:: boxed:: Box ;
810#[ cfg( feature = "alloc" ) ]
911use alloc:: collections:: TryReserveError ;
1012#[ cfg( feature = "alloc" ) ]
1113use 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
3432impl 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 ( "\n Error 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