From 2fce223b8ef947c8b98863f7446e8b061ea704dc 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 | 4 ++-- CHANGELOG.adoc | 7 +++++++ Cargo.toml | 2 +- README.md | 2 +- clippy.toml | 2 +- src/error.rs | 12 +++--------- src/exit_code.rs | 8 +++----- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 0af2cf7..367c65c 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.62.0 # MSRV + - 1.81.0 # MSRV - stable - nightly include: @@ -67,7 +67,7 @@ jobs: - aarch64-apple-darwin - x86_64-pc-windows-msvc toolchain: - - 1.74.0 + - 1.81.0 - stable - nightly include: diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e2b7204..5437948 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,6 +18,13 @@ project adheres to https://semver.org/[Semantic Versioning]. === 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.4\...HEAD[Unreleased] + +=== Changed + * Change MSRV to 1.62.0 ({pull-request-url}/131[#131]) == {compare-url}/v0.8.3\...v0.8.4[0.8.4] - 2024-10-31 diff --git a/Cargo.toml b/Cargo.toml index fbe3580..7225b37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ name = "sysexits" version = "0.8.4" authors = ["Shun Sakai "] edition = "2021" -rust-version = "1.62.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 f238260..e91e172 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.62.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 770283e..c037fdb 100644 --- a/clippy.toml +++ b/clippy.toml @@ -2,4 +2,4 @@ # # SPDX-License-Identifier: Apache-2.0 OR MIT -msrv = "1.62.0" +msrv = "1.81.0" diff --git a/src/error.rs b/src/error.rs index 9acc177..b926dd7 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. @@ -20,8 +20,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 @@ -61,7 +60,7 @@ impl fmt::Display for TryFromExitStatusError { } #[cfg(feature = "std")] -impl std::error::Error for TryFromExitStatusError {} +impl Error for TryFromExitStatusError {} #[cfg(test)] mod tests { @@ -97,11 +96,8 @@ mod tests { ); } - #[cfg(feature = "std")] #[test] fn source_exit_code_range_error() { - use std::error::Error; - assert!(ExitCodeRangeError.source().is_none()); } @@ -190,8 +186,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 a89999f..665b66c 100644 --- a/src/exit_code.rs +++ b/src/exit_code.rs @@ -12,6 +12,8 @@ mod convert; mod fmt; pub mod result; +use core::error::Error; + /// `ExitCode` is a type that represents the system exit code constants as /// defined by [``]. /// @@ -272,8 +274,7 @@ impl ExitCode { } } -#[cfg(feature = "std")] -impl std::error::Error for ExitCode {} +impl Error for ExitCode {} #[cfg(feature = "std")] impl std::process::Termination for ExitCode { @@ -633,11 +634,8 @@ mod tests { assert!(ExitCode::Config.is_failure()); } - #[cfg(feature = "std")] #[test] fn source() { - use std::error::Error; - assert!(ExitCode::Ok.source().is_none()); assert!(ExitCode::Usage.source().is_none()); assert!(ExitCode::DataErr.source().is_none());