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

Add const fn none() #27

Merged
merged 2 commits into from
Jun 30, 2022
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
3 changes: 3 additions & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ impl Duration {
// TODO: duration_constants https://github.com/rust-lang/rust/issues/57391
// TODO: div_duration https://github.com/rust-lang/rust/issues/63139

/// Returns a "none" value
pub const NONE: Self = Self(None);

/// A duration of zero time.
///
/// # Examples
Expand Down
3 changes: 3 additions & 0 deletions src/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ use super::{pair_and_then, Duration, TryFromTimeError};
pub struct Instant(Option<time::Instant>);

impl Instant {
/// Returns a "none" value
pub const NONE: Self = Self(None);

/// Returns an instant corresponding to "now".
///
/// # Examples
Expand Down
5 changes: 5 additions & 0 deletions tests/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ use core::time;

use easytime::Duration;

#[test]
fn none() {
assert!(Duration::NONE.is_none());
}

#[test]
fn cmp() {
assert!(Duration::from_secs(1) == Duration::from_secs(1));
Expand Down
5 changes: 5 additions & 0 deletions tests/instant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub mod std_tests {
}};
}

#[test]
fn none() {
assert!(Instant::NONE.is_none());
}

#[test]
fn instant_monotonic() {
let a = Instant::now();
Expand Down