From c9681c24a28325eed6564295b8458ec562437580 Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Fri, 20 Sep 2024 20:02:07 +0900 Subject: [PATCH] feat: Make `Error` trait available in `no_std` mode --- .github/workflows/CI.yaml | 2 +- CHANGELOG.adoc | 7 +++++++ Cargo.toml | 2 +- README.md | 2 +- clippy.toml | 2 +- src/error.rs | 12 +++--------- src/exit_code.rs | 8 ++------ 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 81d8dce..ead3dd5 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -24,7 +24,7 @@ jobs: - aarch64-apple-darwin - x86_64-pc-windows-msvc toolchain: - - 1.74.0 # MSRV + - 1.81.0 # MSRV - stable - nightly include: diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index cb18631..9999cf6 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -16,6 +16,13 @@ project adheres to https://semver.org/[Semantic Versioning]. == {compare-url}/v0.8.2\...HEAD[Unreleased] +=== Changed + +* Make `Error` trait available in `no_std` mode ({pull-request-url}/116[#116]) +* Bump MSRV to 1.81.0 ({pull-request-url}/116[#116]) + +== {compare-url}/v0.8.2\...HEAD[Unreleased] + === Added * Add benchmarks ({pull-request-url}/121[#121]) diff --git a/Cargo.toml b/Cargo.toml index 423e359..62f8c2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "sysexits" version = "0.8.2" authors = ["Shun Sakai "] edition = "2021" -rust-version = "1.74.0" +rust-version = "1.81.0" description = "The system exit codes as defined by " documentation = "https://docs.rs/sysexits" readme = "README.md" diff --git a/README.md b/README.md index 9c547b8..31f798e 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ See the [documentation][docs-url] for more details. ## Minimum supported Rust version -The minimum supported Rust version (MSRV) of this library is v1.74.0. +The minimum supported Rust version (MSRV) of this library is v1.81.0. ## Source code diff --git a/clippy.toml b/clippy.toml index efb0e67..c037fdb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,4 +2,4 @@ # # SPDX-License-Identifier: Apache-2.0 OR MIT -msrv = "1.74.0" +msrv = "1.81.0" diff --git a/src/error.rs b/src/error.rs index f3f6cc1..e7eff0c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,7 +5,7 @@ //! Error types for this crate. -use core::fmt; +use core::{error::Error, fmt}; /// The error type indicating that [`ExitCode`](crate::ExitCode) was out of /// range. @@ -19,8 +19,7 @@ impl fmt::Display for ExitCodeRangeError { } } -#[cfg(feature = "std")] -impl std::error::Error for ExitCodeRangeError {} +impl Error for ExitCodeRangeError {} #[cfg(feature = "std")] /// An error which can be returned when converting an @@ -59,7 +58,7 @@ impl fmt::Display for TryFromExitStatusError { } #[cfg(feature = "std")] -impl std::error::Error for TryFromExitStatusError {} +impl Error for TryFromExitStatusError {} #[cfg(test)] mod tests { @@ -95,11 +94,8 @@ mod tests { ); } - #[cfg(feature = "std")] #[test] fn source_exit_code_range_error() { - use std::error::Error; - assert!(ExitCodeRangeError.source().is_none()); } @@ -188,8 +184,6 @@ mod tests { #[cfg(feature = "std")] #[test] fn source_try_from_exit_status_error() { - use std::error::Error; - assert!(TryFromExitStatusError::new(Some(1)).source().is_none()); assert!(TryFromExitStatusError::new(None).source().is_none()); } diff --git a/src/exit_code.rs b/src/exit_code.rs index 04da0ee..4341af5 100644 --- a/src/exit_code.rs +++ b/src/exit_code.rs @@ -11,7 +11,7 @@ mod consts; mod convert; pub mod result; -use core::fmt; +use core::{error::Error, fmt}; /// `ExitCode` is a type that represents the system exit code constants as /// defined by [``]. @@ -288,8 +288,7 @@ impl fmt::Display for ExitCode { } } -#[cfg(feature = "std")] -impl std::error::Error for ExitCode {} +impl Error for ExitCode {} #[cfg(feature = "std")] impl std::process::Termination for ExitCode { @@ -664,11 +663,8 @@ mod tests { assert!(ExitCode::Config.is_failure()); } - #[cfg(feature = "std")] #[test] fn source_exit_code() { - use std::error::Error; - assert!(ExitCode::Ok.source().is_none()); assert!(ExitCode::Usage.source().is_none()); assert!(ExitCode::DataErr.source().is_none());