Skip to content

Commit

Permalink
feat: Make Error trait available in no_std mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Sep 20, 2024
1 parent 0a8ee74 commit 814f232
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- aarch64-apple-darwin
- x86_64-pc-windows-msvc
toolchain:
- 1.74.0 # MSRV
- 1.81.0 # MSRV
- stable
include:
- target: x86_64-unknown-linux-gnu
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ project adheres to https://semver.org/[Semantic Versioning].

== {compare-url}/v0.8.1\...HEAD[Unreleased]

=== Changed

* Make `Error` trait available in `no_std` mode ({pull-request-url}/219[#219])
* Bump MSRV to 1.81.0 ({pull-request-url}/219[#219])

=== Removed

* Remove `zip::DateTime` integration ({pull-request-url}/210[#210])
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "nt-time"
version = "0.8.1"
authors = ["Shun Sakai <sorairolake@protonmail.ch>"]
edition = "2021"
rust-version = "1.74.0"
rust-version = "1.81.0"
description = "A Windows file time library"
documentation = "https://docs.rs/nt-time"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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

Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: Apache-2.0 OR MIT

msrv = "1.74.0"
msrv = "1.81.0"
21 changes: 5 additions & 16 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Error types for this crate.

use core::{
error::Error,
fmt,
num::{IntErrorKind, ParseIntError},
};
Expand Down Expand Up @@ -55,8 +56,7 @@ impl fmt::Display for DosDateTimeRangeError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for DosDateTimeRangeError {}
impl Error for DosDateTimeRangeError {}

impl From<DosDateTimeRangeErrorKind> for DosDateTimeRangeError {
fn from(kind: DosDateTimeRangeErrorKind) -> Self {
Expand Down Expand Up @@ -136,8 +136,7 @@ impl fmt::Display for FileTimeRangeError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for FileTimeRangeError {}
impl Error for FileTimeRangeError {}

impl From<FileTimeRangeErrorKind> for FileTimeRangeError {
fn from(kind: FileTimeRangeErrorKind) -> Self {
Expand Down Expand Up @@ -204,10 +203,9 @@ impl fmt::Display for ParseFileTimeError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for ParseFileTimeError {
impl Error for ParseFileTimeError {
#[inline]
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.0)
}
}
Expand Down Expand Up @@ -313,11 +311,8 @@ mod tests {
);
}

#[cfg(feature = "std")]
#[test]
fn source_dos_date_time_range_error() {
use std::error::Error;

assert!(
DosDateTimeRangeError::new(DosDateTimeRangeErrorKind::Negative)
.source()
Expand Down Expand Up @@ -508,11 +503,8 @@ mod tests {
);
}

#[cfg(feature = "std")]
#[test]
fn source_file_time_range_error() {
use std::error::Error;

assert!(FileTimeRangeError::new(FileTimeRangeErrorKind::Negative)
.source()
.is_none());
Expand Down Expand Up @@ -694,11 +686,8 @@ mod tests {
);
}

#[cfg(feature = "std")]
#[test]
fn source_parse_file_time_error() {
use std::error::Error;

assert_eq!(
ParseFileTimeError::new(u64::from_str("").unwrap_err())
.source()
Expand Down
23 changes: 5 additions & 18 deletions src/file_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ impl FromStr for FileTime {

#[cfg(test)]
mod tests {
use core::{
error::Error,
num::{IntErrorKind, ParseIntError},
};

use super::*;

#[test]
Expand Down Expand Up @@ -437,14 +442,8 @@ mod tests {
prop_assert_eq!(FileTime::from_str(&s).unwrap(), FileTime::new(ft));
}

#[cfg(feature = "std")]
#[test]
fn from_str_when_empty() {
use std::{
error::Error,
num::{IntErrorKind, ParseIntError},
};

assert_eq!(
FileTime::from_str("")
.unwrap_err()
Expand All @@ -457,14 +456,8 @@ mod tests {
);
}

#[cfg(feature = "std")]
#[test]
fn from_str_with_invalid_digit() {
use std::{
error::Error,
num::{IntErrorKind, ParseIntError},
};

assert_eq!(
FileTime::from_str("a")
.unwrap_err()
Expand Down Expand Up @@ -537,14 +530,8 @@ mod tests {
prop_assert!(FileTime::from_str(&s).is_err());
}

#[cfg(feature = "std")]
#[test]
fn from_str_when_positive_overflow() {
use std::{
error::Error,
num::{IntErrorKind, ParseIntError},
};

assert_eq!(
FileTime::from_str("18446744073709551616")
.unwrap_err()
Expand Down

0 comments on commit 814f232

Please sign in to comment.