GitXplorerGitXplorer
t

easytime

public
14 stars
2 forks
0 issues

Commits

List of commits on branch main.
Unverified
ced120666292d8ff6a11f47d5a089cdf18f8a3d9

Update Duration todo comments

ttaiki-e committed 2 days ago
Unverified
9ca78cb6044fc0b9fc82e83220589224582978e8

ci: Disable buggy dependabot grouped update

ttaiki-e committed 2 days ago
Unverified
117d538025fc91d874347c13f3b24a1f3e12a196

tools: Format shell scripts with indent_size = 2 to match scripts in CI config

ttaiki-e committed 2 days ago
Unverified
b5b8689b20fdd43aabd9db2a142ab6b31ae2202b

Add MSRV reason comment

ttaiki-e committed 4 days ago
Unverified
c7e98795d31b8856f834b42fcf71b42ff650ebe4

Apply clippy::unused_trait_names lint

ttaiki-e committed 5 days ago
Unverified
0163875c9f297d26badcea6ebc7490e81842cb24

ci: Update reusable workflows

ttaiki-e committed 6 days ago

README

The README file for this repository.

easytime

crates.io docs.rs license msrv github actions

Providing wrapper types for safely performing panic-free checked arithmetic on instants and durations.

This crate provides the following two data structures.

Usage

Add this to your Cargo.toml:

[dependencies]
easytime = "0.2"

Examples

use easytime::{Duration, Instant};
use std::time::Duration as StdDuration;

fn foo(secs: u64, nanos: u32, instant: Instant) -> Option<StdDuration> {
    let now = Instant::now();

    let dur = Duration::new(secs, nanos);
    (now - instant - dur).into_inner()
}

If you use std::time directly, you need to write as follows:

use std::time::{Duration, Instant};

fn foo(secs: u64, nanos: u32, instant: Instant) -> Option<Duration> {
    let now = Instant::now();

    let secs = Duration::from_secs(secs);
    let nanos = Duration::from_nanos(nanos as u64);

    let dur = secs.checked_add(nanos)?;
    now.checked_duration_since(instant)?.checked_sub(dur)
}

Optional features

  • std (enabled by default)
    • Enable to use easytime::Instant.
    • If disabled this feature, easytime can be used in no_std environments.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.