Skip to content

Commit 2a6a07d

Browse files
tormehdjc
authored andcommitted
Make eligible functions const.
1 parent 8fd7ca2 commit 2a6a07d

File tree

11 files changed

+32
-32
lines changed

11 files changed

+32
-32
lines changed

src/format/locales.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
use pure_rust_locales::{locale_match, Locale};
22

3-
pub(crate) fn short_months(locale: Locale) -> &'static [&'static str] {
3+
pub(crate) const fn short_months(locale: Locale) -> &'static [&'static str] {
44
locale_match!(locale => LC_TIME::ABMON)
55
}
66

7-
pub(crate) fn long_months(locale: Locale) -> &'static [&'static str] {
7+
pub(crate) const fn long_months(locale: Locale) -> &'static [&'static str] {
88
locale_match!(locale => LC_TIME::MON)
99
}
1010

11-
pub(crate) fn short_weekdays(locale: Locale) -> &'static [&'static str] {
11+
pub(crate) const fn short_weekdays(locale: Locale) -> &'static [&'static str] {
1212
locale_match!(locale => LC_TIME::ABDAY)
1313
}
1414

15-
pub(crate) fn long_weekdays(locale: Locale) -> &'static [&'static str] {
15+
pub(crate) const fn long_weekdays(locale: Locale) -> &'static [&'static str] {
1616
locale_match!(locale => LC_TIME::DAY)
1717
}
1818

19-
pub(crate) fn am_pm(locale: Locale) -> &'static [&'static str] {
19+
pub(crate) const fn am_pm(locale: Locale) -> &'static [&'static str] {
2020
locale_match!(locale => LC_TIME::AM_PM)
2121
}
2222

23-
pub(crate) fn d_fmt(locale: Locale) -> &'static str {
23+
pub(crate) const fn d_fmt(locale: Locale) -> &'static str {
2424
locale_match!(locale => LC_TIME::D_FMT)
2525
}
2626

27-
pub(crate) fn d_t_fmt(locale: Locale) -> &'static str {
27+
pub(crate) const fn d_t_fmt(locale: Locale) -> &'static str {
2828
locale_match!(locale => LC_TIME::D_T_FMT)
2929
}
3030

31-
pub(crate) fn t_fmt(locale: Locale) -> &'static str {
31+
pub(crate) const fn t_fmt(locale: Locale) -> &'static str {
3232
locale_match!(locale => LC_TIME::T_FMT)
3333
}

src/format/scan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ fn timezone_offset_internal<F>(
254254
where
255255
F: FnMut(&str) -> ParseResult<&str>,
256256
{
257-
fn digits(s: &str) -> ParseResult<(u8, u8)> {
257+
const fn digits(s: &str) -> ParseResult<(u8, u8)> {
258258
let b = s.as_bytes();
259259
if b.len() < 2 {
260260
Err(TOO_SHORT)

src/month.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl Month {
6666
/// `m.succ()`: | `February` | `March` | `...` | `January`
6767
#[inline]
6868
#[must_use]
69-
pub fn succ(&self) -> Month {
69+
pub const fn succ(&self) -> Month {
7070
match *self {
7171
Month::January => Month::February,
7272
Month::February => Month::March,
@@ -90,7 +90,7 @@ impl Month {
9090
/// `m.pred()`: | `December` | `January` | `...` | `November`
9191
#[inline]
9292
#[must_use]
93-
pub fn pred(&self) -> Month {
93+
pub const fn pred(&self) -> Month {
9494
match *self {
9595
Month::January => Month::December,
9696
Month::February => Month::January,
@@ -114,7 +114,7 @@ impl Month {
114114
/// `m.number_from_month()`: | 1 | 2 | `...` | 12
115115
#[inline]
116116
#[must_use]
117-
pub fn number_from_month(&self) -> u32 {
117+
pub const fn number_from_month(&self) -> u32 {
118118
match *self {
119119
Month::January => 1,
120120
Month::February => 2,
@@ -139,7 +139,7 @@ impl Month {
139139
/// assert_eq!(Month::January.name(), "January")
140140
/// ```
141141
#[must_use]
142-
pub fn name(&self) -> &'static str {
142+
pub const fn name(&self) -> &'static str {
143143
match *self {
144144
Month::January => "January",
145145
Month::February => "February",

src/naive/internals.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl Of {
301301
}
302302

303303
#[inline]
304-
pub(super) fn with_ordinal(&self, ordinal: u32) -> Option<Of> {
304+
pub(super) const fn with_ordinal(&self, ordinal: u32) -> Option<Of> {
305305
if ordinal > 366 {
306306
return None;
307307
}
@@ -405,7 +405,7 @@ impl Mdf {
405405
}
406406

407407
#[inline]
408-
pub(super) fn with_month(&self, month: u32) -> Option<Mdf> {
408+
pub(super) const fn with_month(&self, month: u32) -> Option<Mdf> {
409409
if month > 12 {
410410
return None;
411411
}
@@ -421,7 +421,7 @@ impl Mdf {
421421
}
422422

423423
#[inline]
424-
pub(super) fn with_day(&self, day: u32) -> Option<Mdf> {
424+
pub(super) const fn with_day(&self, day: u32) -> Option<Mdf> {
425425
if day > 31 {
426426
return None;
427427
}

src/naive/time/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl NaiveTime {
241241
/// ```
242242
#[inline]
243243
#[must_use]
244-
pub fn from_hms_opt(hour: u32, min: u32, sec: u32) -> Option<NaiveTime> {
244+
pub const fn from_hms_opt(hour: u32, min: u32, sec: u32) -> Option<NaiveTime> {
245245
NaiveTime::from_hms_nano_opt(hour, min, sec, 0)
246246
}
247247

@@ -366,7 +366,7 @@ impl NaiveTime {
366366
/// ```
367367
#[inline]
368368
#[must_use]
369-
pub fn from_hms_nano_opt(hour: u32, min: u32, sec: u32, nano: u32) -> Option<NaiveTime> {
369+
pub const fn from_hms_nano_opt(hour: u32, min: u32, sec: u32, nano: u32) -> Option<NaiveTime> {
370370
if hour >= 24 || min >= 60 || sec >= 60 || nano >= 2_000_000_000 {
371371
return None;
372372
}
@@ -409,7 +409,7 @@ impl NaiveTime {
409409
/// ```
410410
#[inline]
411411
#[must_use]
412-
pub fn from_num_seconds_from_midnight_opt(secs: u32, nano: u32) -> Option<NaiveTime> {
412+
pub const fn from_num_seconds_from_midnight_opt(secs: u32, nano: u32) -> Option<NaiveTime> {
413413
if secs >= 86_400 || nano >= 2_000_000_000 {
414414
return None;
415415
}

src/offset/fixed.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl FixedOffset {
5555
/// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00+05:00")
5656
/// ```
5757
#[must_use]
58-
pub fn east_opt(secs: i32) -> Option<FixedOffset> {
58+
pub const fn east_opt(secs: i32) -> Option<FixedOffset> {
5959
if -86_400 < secs && secs < 86_400 {
6060
Some(FixedOffset { local_minus_utc: secs })
6161
} else {
@@ -89,7 +89,7 @@ impl FixedOffset {
8989
/// assert_eq!(&datetime.to_rfc3339(), "2016-11-08T00:00:00-05:00")
9090
/// ```
9191
#[must_use]
92-
pub fn west_opt(secs: i32) -> Option<FixedOffset> {
92+
pub const fn west_opt(secs: i32) -> Option<FixedOffset> {
9393
if -86_400 < secs && secs < 86_400 {
9494
Some(FixedOffset { local_minus_utc: -secs })
9595
} else {

src/offset/local/tz_info/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a> Cursor<'a> {
237237
}
238238

239239
/// Returns `true` if data is remaining
240-
pub(crate) fn is_empty(&self) -> bool {
240+
pub(crate) const fn is_empty(&self) -> bool {
241241
self.remaining.is_empty()
242242
}
243243

src/offset/local/tz_info/rule.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub(super) struct AlternateTime {
127127

128128
impl AlternateTime {
129129
/// Construct a transition rule representing alternate local time types
130-
fn new(
130+
const fn new(
131131
std: LocalTimeType,
132132
dst: LocalTimeType,
133133
dst_start: RuleDay,
@@ -504,7 +504,7 @@ impl RuleDay {
504504
}
505505

506506
/// Construct a transition rule day represented by a zero-based Julian day in `[0, 365]`, taking occasional Feb 29 into account
507-
fn julian_0(julian_day_0: u16) -> Result<Self, Error> {
507+
const fn julian_0(julian_day_0: u16) -> Result<Self, Error> {
508508
if julian_day_0 > 365 {
509509
return Err(Error::TransitionRule("invalid rule day julian day"));
510510
}
@@ -737,7 +737,7 @@ const DAY_IN_MONTHS_LEAP_YEAR_FROM_MARCH: [i64; 12] =
737737
/// * `year`: Year
738738
/// * `month`: Month in `[1, 12]`
739739
/// * `month_day`: Day of the month in `[1, 31]`
740-
pub(crate) fn days_since_unix_epoch(year: i32, month: usize, month_day: i64) -> i64 {
740+
pub(crate) const fn days_since_unix_epoch(year: i32, month: usize, month_day: i64) -> i64 {
741741
let is_leap_year = is_leap_year(year);
742742

743743
let year = year as i64;
@@ -768,7 +768,7 @@ pub(crate) fn days_since_unix_epoch(year: i32, month: usize, month_day: i64) ->
768768
}
769769

770770
/// Check if a year is a leap year
771-
pub(crate) fn is_leap_year(year: i32) -> bool {
771+
pub(crate) const fn is_leap_year(year: i32) -> bool {
772772
year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)
773773
}
774774

src/offset/local/tz_info/timezone.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl<'a> TimeZoneRef<'a> {
374374
}
375375

376376
/// Convert Unix time to Unix leap time, from the list of leap seconds in a time zone
377-
fn unix_time_to_unix_leap_time(&self, unix_time: i64) -> Result<i64, Error> {
377+
const fn unix_time_to_unix_leap_time(&self, unix_time: i64) -> Result<i64, Error> {
378378
let mut unix_leap_time = unix_time;
379379

380380
let mut i = 0;
@@ -563,7 +563,7 @@ impl LocalTimeType {
563563
}
564564

565565
/// Construct a local time type with the specified UTC offset in seconds
566-
pub(super) fn with_offset(ut_offset: i32) -> Result<Self, Error> {
566+
pub(super) const fn with_offset(ut_offset: i32) -> Result<Self, Error> {
567567
if ut_offset == i32::min_value() {
568568
return Err(Error::LocalTimeType("invalid UTC offset"));
569569
}
@@ -608,7 +608,7 @@ fn find_tz_file(path: impl AsRef<Path>) -> Result<File, Error> {
608608
}
609609

610610
#[inline]
611-
fn saturating_abs(v: i32) -> i32 {
611+
const fn saturating_abs(v: i32) -> i32 {
612612
if v.is_positive() {
613613
v
614614
} else if v == i32::min_value() {

src/round.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ where
7575
}
7676

7777
// Return the maximum span in nanoseconds for the target number of digits.
78-
fn span_for_digits(digits: u16) -> u32 {
78+
const fn span_for_digits(digits: u16) -> u32 {
7979
// fast lookup form of: 10^(9-min(9,digits))
8080
match digits {
8181
0 => 1_000_000_000,

src/weekday.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl Weekday {
5757
/// `w.succ()`: | `Tue` | `Wed` | `Thu` | `Fri` | `Sat` | `Sun` | `Mon`
5858
#[inline]
5959
#[must_use]
60-
pub fn succ(&self) -> Weekday {
60+
pub const fn succ(&self) -> Weekday {
6161
match *self {
6262
Weekday::Mon => Weekday::Tue,
6363
Weekday::Tue => Weekday::Wed,
@@ -76,7 +76,7 @@ impl Weekday {
7676
/// `w.pred()`: | `Sun` | `Mon` | `Tue` | `Wed` | `Thu` | `Fri` | `Sat`
7777
#[inline]
7878
#[must_use]
79-
pub fn pred(&self) -> Weekday {
79+
pub const fn pred(&self) -> Weekday {
8080
match *self {
8181
Weekday::Mon => Weekday::Sun,
8282
Weekday::Tue => Weekday::Mon,

0 commit comments

Comments
 (0)