Skip to content

Commit db6e6e4

Browse files
authored
feat: Expose core::error::Error without the std feature (#443)
Since Rust 1.81.0, the std::error::Error type is just a reexport from core, so we can finally expose it even in no_std environments! I’ve tested that everything builds against rustc 1.81.0.
1 parent 4e6f27a commit db6e6e4

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

compact_str/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ version = "0.9.0"
55
authors = ["Parker Timmerman <parker@parkertimmerman.com>"]
66
edition = "2021"
77
license = "MIT"
8+
rust-version = "1.81" # For core::error::Error
89
homepage = "https://github.com/ParkMyCar/compact_str"
910
repository = "https://github.com/ParkMyCar/compact_str"
1011
readme = "../README.md"

compact_str/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,12 +2200,11 @@ impl From<CompactString> for alloc::rc::Rc<str> {
22002200
}
22012201
}
22022202

2203-
#[cfg(feature = "std")]
2204-
impl From<CompactString> for Box<dyn std::error::Error + Send + Sync> {
2203+
impl From<CompactString> for Box<dyn core::error::Error + Send + Sync> {
22052204
fn from(value: CompactString) -> Self {
22062205
struct StringError(CompactString);
22072206

2208-
impl std::error::Error for StringError {
2207+
impl core::error::Error for StringError {
22092208
#[allow(deprecated)]
22102209
fn description(&self) -> &str {
22112210
&self.0
@@ -2229,11 +2228,10 @@ impl From<CompactString> for Box<dyn std::error::Error + Send + Sync> {
22292228
}
22302229
}
22312230

2232-
#[cfg(feature = "std")]
2233-
impl From<CompactString> for Box<dyn std::error::Error> {
2231+
impl From<CompactString> for Box<dyn core::error::Error> {
22342232
fn from(value: CompactString) -> Self {
2235-
let err1: Box<dyn std::error::Error + Send + Sync> = From::from(value);
2236-
let err2: Box<dyn std::error::Error> = err1;
2233+
let err1: Box<dyn core::error::Error + Send + Sync> = From::from(value);
2234+
let err2: Box<dyn core::error::Error> = err1;
22372235
err2
22382236
}
22392237
}
@@ -2586,9 +2584,7 @@ impl fmt::Display for ReserveError {
25862584
}
25872585
}
25882586

2589-
#[cfg(feature = "std")]
2590-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
2591-
impl std::error::Error for ReserveError {}
2587+
impl core::error::Error for ReserveError {}
25922588

25932589
/// A possible error value if [`ToCompactString::try_to_compact_string()`] failed.
25942590
#[derive(Debug, Clone, Copy, PartialEq)]
@@ -2623,10 +2619,8 @@ impl From<fmt::Error> for ToCompactStringError {
26232619
}
26242620
}
26252621

2626-
#[cfg(feature = "std")]
2627-
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
2628-
impl std::error::Error for ToCompactStringError {
2629-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
2622+
impl core::error::Error for ToCompactStringError {
2623+
fn source(&self) -> Option<&(dyn core::error::Error + 'static)> {
26302624
match self {
26312625
ToCompactStringError::Reserve(err) => Some(err),
26322626
ToCompactStringError::Fmt(err) => Some(err),

0 commit comments

Comments
 (0)