Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make eligible functions const. #984

Merged
merged 1 commit into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ pub struct ParseError(ParseErrorKind);

impl ParseError {
/// The category of parse error
pub fn kind(&self) -> ParseErrorKind {
pub const fn kind(&self) -> ParseErrorKind {
self.0
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/month.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub struct Months(pub(crate) u32);

impl Months {
/// Construct a new `Months` from a number of months
pub fn new(num: u32) -> Self {
pub const fn new(num: u32) -> Self {
Self(num)
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub struct Days(pub(crate) u64);

impl Days {
/// Construct a new `Days` from a number of days
pub fn new(num: u64) -> Self {
pub const fn new(num: u64) -> Self {
Self(num)
}
}
Expand Down Expand Up @@ -708,7 +708,7 @@ impl NaiveDate {
/// assert_eq!(dt.time(), t);
/// ```
#[inline]
pub fn and_time(&self, time: NaiveTime) -> NaiveDateTime {
pub const fn and_time(&self, time: NaiveTime) -> NaiveDateTime {
NaiveDateTime::new(*self, time)
}

Expand Down Expand Up @@ -898,7 +898,7 @@ impl NaiveDate {

/// Returns the packed ordinal-flags.
#[inline]
fn of(&self) -> Of {
const fn of(&self) -> Of {
Of((self.ymdf & 0b1_1111_1111_1111) as u32)
}

Expand Down Expand Up @@ -1221,7 +1221,7 @@ impl NaiveDate {
/// }
/// ```
#[inline]
pub fn iter_days(&self) -> NaiveDateDaysIterator {
pub const fn iter_days(&self) -> NaiveDateDaysIterator {
NaiveDateDaysIterator { value: *self }
}

Expand Down Expand Up @@ -1252,14 +1252,14 @@ impl NaiveDate {
/// }
/// ```
#[inline]
pub fn iter_weeks(&self) -> NaiveDateWeeksIterator {
pub const fn iter_weeks(&self) -> NaiveDateWeeksIterator {
NaiveDateWeeksIterator { value: *self }
}

/// Returns the [`NaiveWeek`] that the date belongs to, starting with the [`Weekday`]
/// specified.
#[inline]
pub fn week(&self, start: Weekday) -> NaiveWeek {
pub const fn week(&self, start: Weekday) -> NaiveWeek {
NaiveWeek { date: *self, start }
}

Expand Down
6 changes: 3 additions & 3 deletions src/naive/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl NaiveDateTime {
/// assert_eq!(dt.time(), t);
/// ```
#[inline]
pub fn new(date: NaiveDate, time: NaiveTime) -> NaiveDateTime {
pub const fn new(date: NaiveDate, time: NaiveTime) -> NaiveDateTime {
NaiveDateTime { date, time }
}

Expand Down Expand Up @@ -335,7 +335,7 @@ impl NaiveDateTime {
/// assert_eq!(dt.date(), NaiveDate::from_ymd_opt(2016, 7, 8).unwrap());
/// ```
#[inline]
pub fn date(&self) -> NaiveDate {
pub const fn date(&self) -> NaiveDate {
self.date
}

Expand All @@ -350,7 +350,7 @@ impl NaiveDateTime {
/// assert_eq!(dt.time(), NaiveTime::from_hms_opt(9, 10, 11).unwrap());
/// ```
#[inline]
pub fn time(&self) -> NaiveTime {
pub const fn time(&self) -> NaiveTime {
self.time
}

Expand Down
14 changes: 7 additions & 7 deletions src/naive/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl YearFlags {
}

#[inline]
pub(super) fn nisoweeks(&self) -> u32 {
pub(super) const fn nisoweeks(&self) -> u32 {
let YearFlags(flags) = *self;
52 + ((0b0000_0100_0000_0110 >> flags as usize) & 1)
}
Expand Down Expand Up @@ -294,7 +294,7 @@ impl Of {
}

#[inline]
pub(super) fn ordinal(&self) -> u32 {
pub(super) const fn ordinal(&self) -> u32 {
let Of(of) = *self;
of >> 4
}
Expand All @@ -310,7 +310,7 @@ impl Of {
}

#[inline]
pub(super) fn flags(&self) -> YearFlags {
pub(super) const fn flags(&self) -> YearFlags {
let Of(of) = *self;
YearFlags((of & 0b1111) as u8)
}
Expand All @@ -336,13 +336,13 @@ impl Of {
}

#[inline]
pub(super) fn succ(&self) -> Of {
pub(super) const fn succ(&self) -> Of {
let Of(of) = *self;
Of(of + (1 << 4))
}

#[inline]
pub(super) fn pred(&self) -> Of {
pub(super) const fn pred(&self) -> Of {
let Of(of) = *self;
Of(of - (1 << 4))
}
Expand Down Expand Up @@ -398,7 +398,7 @@ impl Mdf {
}

#[inline]
pub(super) fn month(&self) -> u32 {
pub(super) const fn month(&self) -> u32 {
let Mdf(mdf) = *self;
mdf >> 9
}
Expand All @@ -414,7 +414,7 @@ impl Mdf {
}

#[inline]
pub(super) fn day(&self) -> u32 {
pub(super) const fn day(&self) -> u32 {
let Mdf(mdf) = *self;
(mdf >> 4) & 0b1_1111
}
Expand Down
6 changes: 3 additions & 3 deletions src/naive/isoweek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl IsoWeek {
/// assert_eq!(d, NaiveDate::from_ymd_opt(2014, 12, 29).unwrap());
/// ```
#[inline]
pub fn year(&self) -> i32 {
pub const fn year(&self) -> i32 {
self.ywf >> 10
}

Expand All @@ -88,7 +88,7 @@ impl IsoWeek {
/// assert_eq!(d.iso_week().week(), 15);
/// ```
#[inline]
pub fn week(&self) -> u32 {
pub const fn week(&self) -> u32 {
((self.ywf >> 4) & 0x3f) as u32
}

Expand All @@ -105,7 +105,7 @@ impl IsoWeek {
/// assert_eq!(d.iso_week().week0(), 14);
/// ```
#[inline]
pub fn week0(&self) -> u32 {
pub const fn week0(&self) -> u32 {
((self.ywf >> 4) & 0x3f) as u32 - 1
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/offset/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ impl FixedOffset {

/// Returns the number of seconds to add to convert from UTC to the local time.
#[inline]
pub fn local_minus_utc(&self) -> i32 {
pub const fn local_minus_utc(&self) -> i32 {
self.local_minus_utc
}

/// Returns the number of seconds to add to convert from the local time to UTC.
#[inline]
pub fn utc_minus_local(&self) -> i32 {
pub const fn utc_minus_local(&self) -> i32 {
-self.local_minus_utc
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/offset/local/tz_info/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub(crate) struct Cursor<'a> {

impl<'a> Cursor<'a> {
/// Construct a new `Cursor` from remaining data
pub(crate) fn new(remaining: &'a [u8]) -> Self {
pub(crate) const fn new(remaining: &'a [u8]) -> Self {
Self { remaining, read_count: 0 }
}

Expand All @@ -233,7 +233,7 @@ impl<'a> Cursor<'a> {
}

/// Returns remaining data
pub(crate) fn remaining(&self) -> &'a [u8] {
pub(crate) const fn remaining(&self) -> &'a [u8] {
self.remaining
}

Expand Down
12 changes: 6 additions & 6 deletions src/offset/local/tz_info/timezone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,12 @@ pub(super) struct Transition {

impl Transition {
/// Construct a TZif file transition
pub(super) fn new(unix_leap_time: i64, local_time_type_index: usize) -> Self {
pub(super) const fn new(unix_leap_time: i64, local_time_type_index: usize) -> Self {
Self { unix_leap_time, local_time_type_index }
}

/// Returns Unix leap time
fn unix_leap_time(&self) -> i64 {
const fn unix_leap_time(&self) -> i64 {
self.unix_leap_time
}
}
Expand All @@ -459,12 +459,12 @@ pub(super) struct LeapSecond {

impl LeapSecond {
/// Construct a TZif file leap second
pub(super) fn new(unix_leap_time: i64, correction: i32) -> Self {
pub(super) const fn new(unix_leap_time: i64, correction: i32) -> Self {
Self { unix_leap_time, correction }
}

/// Returns Unix leap time
fn unix_leap_time(&self) -> i64 {
const fn unix_leap_time(&self) -> i64 {
self.unix_leap_time
}
}
Expand Down Expand Up @@ -572,12 +572,12 @@ impl LocalTimeType {
}

/// Returns offset from UTC in seconds
pub(crate) fn offset(&self) -> i32 {
pub(crate) const fn offset(&self) -> i32 {
self.ut_offset
}

/// Returns daylight saving time indicator
pub(super) fn is_dst(&self) -> bool {
pub(super) const fn is_dst(&self) -> bool {
self.is_dst
}

Expand Down
Loading