Skip to content

Commit e9dcd92

Browse files
committed
Merge pull request #112 from jwodder/gh-101
Add `std` feature/`no_std` support
2 parents 96e7ec5 + d173fa7 commit e9dcd92

File tree

11 files changed

+85
-41
lines changed

11 files changed

+85
-41
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ resolver = "2"
44

55
[workspace.package]
66
edition = "2021"
7-
rust-version = "1.67"
7+
rust-version = "1.81"
88
authors = ["John Thorvald Wodder II <[email protected]>"]
99
repository = "https://github.com/jwodder/julian-rs"
1010
license = "MIT"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
22
[![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml)
33
[![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs)
4-
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org)
4+
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org)
55
[![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT)
66

77
This is a Rust [workspace][] containing various packages for converting between

crates/julian-cli/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
v0.7.0 (in development)
2+
-----------------------
3+
- Increased MSRV to 1.81
4+
15
v0.6.1 (2024-12-18)
26
-------------------
37
- Fix name of installed executable

crates/julian-cli/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
22
[![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml)
33
[![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs)
4-
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org)
4+
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org)
55
[![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT)
66

77
[GitHub](https://github.com/jwodder/julian-rs) | [crates.io](https://crates.io/crates/julian-cli) | [Issues](https://github.com/jwodder/julian-rs/issues) | [Changelog](https://github.com/jwodder/julian-rs/blob/master/crates/julian-cli/CHANGELOG.md)

crates/julian/CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.7.0 (in development)
2+
-----------------------
3+
- Increased MSRV to 1.81
4+
- Added `std` feature for toggling `no_std` support
5+
16
v0.6.0 (2024-12-18)
27
-------------------
38
- Increased MSRV to 1.67

crates/julian/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ categories = ["date-and-time"]
1212

1313
[dependencies]
1414
chrono = { version = "0.4.38", optional = true, default-features = false }
15-
thiserror = "2.0.0"
15+
thiserror = { version = "2.0.0", default-features = false }
1616

1717
[dev-dependencies]
1818
assert_matches = "1.5.0"
1919
rstest = { version = "0.23.0", default-features = false }
2020
rstest_reuse = "0.7.0"
2121

2222
[features]
23+
default = ["std"]
2324
chrono = ["dep:chrono"]
25+
std = []
2426

2527
[lints]
2628
workspace = true

crates/julian/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
22
[![CI Status](https://github.com/jwodder/julian-rs/actions/workflows/test.yml/badge.svg)](https://github.com/jwodder/julian-rs/actions/workflows/test.yml)
33
[![codecov.io](https://codecov.io/gh/jwodder/julian-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/julian-rs)
4-
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.67-orange)](https://www.rust-lang.org)
4+
[![Minimum Supported Rust Version](https://img.shields.io/badge/MSRV-1.81-orange)](https://www.rust-lang.org)
55
[![MIT License](https://img.shields.io/github/license/jwodder/julian-rs.svg)](https://opensource.org/licenses/MIT)
66

77
[GitHub](https://github.com/jwodder/julian-rs) | [crates.io](https://crates.io/crates/julian) | [Documentation](https://docs.rs/julian) | [Issues](https://github.com/jwodder/julian-rs/issues) | [Changelog](https://github.com/jwodder/julian-rs/blob/master/crates/julian/CHANGELOG.md)

crates/julian/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Error types
22
use crate::Month;
3-
use std::num::ParseIntError;
3+
use core::num::ParseIntError;
44
use thiserror::Error;
55

66
#[cfg(feature = "chrono")]

crates/julian/src/inner.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{errors::ParseDateError, Jdnum, Month, COMMON_YEAR_LENGTH, LEAP_YEAR_LENGTH};
2-
use std::cmp::Ordering;
3-
use std::hash::{Hash, Hasher};
2+
use core::cmp::Ordering;
3+
use core::hash::{Hash, Hasher};
44

55
// Julian-calendar year in which Julian day number 0 occurs
66
const JDN0_YEAR: i32 = -4712;
@@ -192,7 +192,7 @@ impl<'a> DateParser<'a> {
192192
pub(crate) fn parse_int(&mut self) -> Result<i32, ParseDateError> {
193193
let mut first = true;
194194
match scan(self.data, |c| {
195-
(std::mem::replace(&mut first, false) && (c == '-' || c == '+')) || c.is_ascii_digit()
195+
(core::mem::replace(&mut first, false) && (c == '-' || c == '+')) || c.is_ascii_digit()
196196
}) {
197197
("", _) => match self.data.chars().next() {
198198
Some(got) => Err(ParseDateError::InvalidIntStart { got }),

crates/julian/src/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Iterator types
22
use crate::{Date, Month, MonthShape};
3-
use std::iter::FusedIterator;
4-
use std::ops::RangeInclusive;
3+
use core::iter::FusedIterator;
4+
use core::ops::RangeInclusive;
55

66
/// An iterator over the days of a month.
77
///

crates/julian/src/lib.rs

+63-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg_attr(not(test), no_std)]
12
#![cfg_attr(docsrs, feature(doc_cfg))]
23
//! `julian` is a Rust library for converting between [Julian day numbers][jdn]
34
//! and dates in the [Gregorian calendar][] (either proleptic or with the
@@ -12,7 +13,11 @@
1213
//! Features
1314
//! ========
1415
//!
15-
//! The `julian` crate has the following optional feature:
16+
//! The `julian` crate has the following optional features:
17+
//!
18+
//! - `std` — This feature is enabled by default; disable it to build in no-std
19+
//! mode. When this feature is disabled, functions that use
20+
//! [`std::time::SystemTime`] are not available.
1621
//!
1722
//! - `chrono` — Enables converting values of certain `julian` types to the
1823
//! corresponding [`chrono`] types and *vice versa*.
@@ -172,10 +177,15 @@ pub mod iter;
172177
pub mod ncal;
173178
use crate::errors::*;
174179
use crate::iter::*;
175-
use std::cmp::Ordering;
176-
use std::fmt;
177-
use std::ops::RangeInclusive;
178-
use std::str::FromStr;
180+
use core::cmp::Ordering;
181+
use core::fmt;
182+
use core::ops::RangeInclusive;
183+
use core::str::FromStr;
184+
185+
#[cfg(feature = "std")]
186+
extern crate std;
187+
188+
#[cfg(feature = "std")]
179189
use std::time::{SystemTime, UNIX_EPOCH};
180190

181191
/// Type used for Julian day numbers in this crate
@@ -396,6 +406,8 @@ impl Calendar {
396406
/// converting the time. This can only happen if the system time in UTC is
397407
/// before -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03
398408
/// (5874777-10-17 O.S.).
409+
#[cfg(feature = "std")]
410+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
399411
pub fn now(&self) -> Result<(Date, u32), ArithmeticError> {
400412
self.at_system_time(SystemTime::now())
401413
}
@@ -409,6 +421,8 @@ impl Calendar {
409421
/// converting the time. This can only happen if the system time in UTC is
410422
/// before -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03
411423
/// (5874777-10-17 O.S.).
424+
#[cfg(feature = "std")]
425+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
412426
pub fn at_system_time(&self, t: SystemTime) -> Result<(Date, u32), ArithmeticError> {
413427
let (jdn, secs) = system2jdn(t)?;
414428
Ok((self.at_jdn(jdn), secs))
@@ -2134,21 +2148,32 @@ impl FromStr for Month {
21342148
/// Parses a month from either its English name or just the first three
21352149
/// letters of the name. Input is treated case-insensitively.
21362150
fn from_str(s: &str) -> Result<Month, ParseMonthError> {
2137-
use Month::*;
2138-
match s.to_ascii_lowercase().as_str() {
2139-
"january" | "jan" => Ok(January),
2140-
"february" | "feb" => Ok(February),
2141-
"march" | "mar" => Ok(March),
2142-
"april" | "apr" => Ok(April),
2143-
"may" => Ok(May),
2144-
"june" | "jun" => Ok(June),
2145-
"july" | "jul" => Ok(July),
2146-
"august" | "aug" => Ok(August),
2147-
"september" | "sep" => Ok(September),
2148-
"october" | "oct" => Ok(October),
2149-
"november" | "nov" => Ok(November),
2150-
"december" | "dec" => Ok(December),
2151-
_ => Err(ParseMonthError),
2151+
if s.eq_ignore_ascii_case("january") || s.eq_ignore_ascii_case("jan") {
2152+
Ok(Month::January)
2153+
} else if s.eq_ignore_ascii_case("february") || s.eq_ignore_ascii_case("feb") {
2154+
Ok(Month::February)
2155+
} else if s.eq_ignore_ascii_case("march") || s.eq_ignore_ascii_case("mar") {
2156+
Ok(Month::March)
2157+
} else if s.eq_ignore_ascii_case("april") || s.eq_ignore_ascii_case("apr") {
2158+
Ok(Month::April)
2159+
} else if s.eq_ignore_ascii_case("may") {
2160+
Ok(Month::May)
2161+
} else if s.eq_ignore_ascii_case("june") || s.eq_ignore_ascii_case("jun") {
2162+
Ok(Month::June)
2163+
} else if s.eq_ignore_ascii_case("july") || s.eq_ignore_ascii_case("jul") {
2164+
Ok(Month::July)
2165+
} else if s.eq_ignore_ascii_case("august") || s.eq_ignore_ascii_case("aug") {
2166+
Ok(Month::August)
2167+
} else if s.eq_ignore_ascii_case("september") || s.eq_ignore_ascii_case("sep") {
2168+
Ok(Month::September)
2169+
} else if s.eq_ignore_ascii_case("october") || s.eq_ignore_ascii_case("oct") {
2170+
Ok(Month::October)
2171+
} else if s.eq_ignore_ascii_case("november") || s.eq_ignore_ascii_case("nov") {
2172+
Ok(Month::November)
2173+
} else if s.eq_ignore_ascii_case("december") || s.eq_ignore_ascii_case("dec") {
2174+
Ok(Month::December)
2175+
} else {
2176+
Err(ParseMonthError)
21522177
}
21532178
}
21542179
}
@@ -2366,16 +2391,22 @@ impl FromStr for Weekday {
23662391
/// Parses a weekday from either its English name or just the first three
23672392
/// letters of the name. Input is treated case-insensitively.
23682393
fn from_str(s: &str) -> Result<Weekday, ParseWeekdayError> {
2369-
use Weekday::*;
2370-
match s.to_ascii_lowercase().as_str() {
2371-
"sunday" | "sun" => Ok(Sunday),
2372-
"monday" | "mon" => Ok(Monday),
2373-
"tuesday" | "tue" => Ok(Tuesday),
2374-
"wednesday" | "wed" => Ok(Wednesday),
2375-
"thursday" | "thu" => Ok(Thursday),
2376-
"friday" | "fri" => Ok(Friday),
2377-
"saturday" | "sat" => Ok(Saturday),
2378-
_ => Err(ParseWeekdayError),
2394+
if s.eq_ignore_ascii_case("sunday") || s.eq_ignore_ascii_case("sun") {
2395+
Ok(Weekday::Sunday)
2396+
} else if s.eq_ignore_ascii_case("monday") || s.eq_ignore_ascii_case("mon") {
2397+
Ok(Weekday::Monday)
2398+
} else if s.eq_ignore_ascii_case("tuesday") || s.eq_ignore_ascii_case("tue") {
2399+
Ok(Weekday::Tuesday)
2400+
} else if s.eq_ignore_ascii_case("wednesday") || s.eq_ignore_ascii_case("wed") {
2401+
Ok(Weekday::Wednesday)
2402+
} else if s.eq_ignore_ascii_case("thursday") || s.eq_ignore_ascii_case("thu") {
2403+
Ok(Weekday::Thursday)
2404+
} else if s.eq_ignore_ascii_case("friday") || s.eq_ignore_ascii_case("fri") {
2405+
Ok(Weekday::Friday)
2406+
} else if s.eq_ignore_ascii_case("saturday") || s.eq_ignore_ascii_case("sat") {
2407+
Ok(Weekday::Saturday)
2408+
} else {
2409+
Err(ParseWeekdayError)
23792410
}
23802411
}
23812412
}
@@ -2446,6 +2477,8 @@ impl From<Weekday> for chrono::Weekday {
24462477
/// conversion. This can only happen if the system time in UTC is before
24472478
/// -5884323-05-15 (-5884202-03-16 O.S.) or after 5874898-06-03 (5874777-10-17
24482479
/// O.S.).
2480+
#[cfg(feature = "std")]
2481+
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
24492482
pub fn system2jdn(t: SystemTime) -> Result<(Jdnum, u32), ArithmeticError> {
24502483
let ts = match t.duration_since(UNIX_EPOCH) {
24512484
Ok(d) => i64::try_from(d.as_secs()),

0 commit comments

Comments
 (0)