Skip to content
This repository was archived by the owner on Jun 6, 2026. It is now read-only.
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
412 changes: 292 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

[workspace]
members = ["fastimer", "fastimer-driver", "fastimer-tokio", "xtask"]
members = ["fastimer", "fastimer-core", "fastimer-tokio", "xtask"]
resolver = "2"

[workspace.package]
Expand All @@ -23,20 +23,30 @@ license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/fast/fastimer"
rust-version = "1.85.0"
version = "0.9.0"

[workspace.dependencies]
fastimer = { version = "0.9.0", path = "fastimer" }
tokio = { version = "1.43.0" }
# Workspace dependencies
fastimer-core = { version = "0.1.0", path = "fastimer-core" }
fastimer-tokio = { version = "0.10.0", path = "fastimer-tokio" }

# Crates.io dependencies
clap = { version = "4.5.20", features = ["derive"] }
log = { version = "0.4.28" }
logforth = { version = "0.28.1" }
pin-project = { version = "1.1.10" }
tokio = { version = "1.47.1" }
which = { version = "8.0.0" }

[workspace.lints.rust]
missing_docs = "deny"
unknown_lints = "deny"
unused_must_use = "deny"

[workspace.lints.clippy]
dbg_macro = "deny"

[workspace.metadata.release]
pre-release-commit-message = "chore: release v{{version}}"
shared-version = true
pre-release-commit-message = "chore: Release {{crate_name}} version {{version}}"
sign-commit = true
sign-tag = true
tag-name = "v{{version}}"
tag-message = "chore: Release {{crate_name}} version {{version}}"
15 changes: 3 additions & 12 deletions fastimer-driver/Cargo.toml → fastimer-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,21 @@
# limitations under the License.

[package]
name = "fastimer-driver"
name = "fastimer-core"
version = "0.1.0"

description = "This crate implements a timer driver that can work with any async runtime scheduler."
description = "Core timer traits, types, and utilities for fastimer"
readme = "README.md"

edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
atomic-waker = { version = "1.1.2" }
crossbeam-queue = { version = "0.3.12" }
fastimer = { workspace = true }
parking = { version = "2.2.1" }

[dev-dependencies]
tokio = { workspace = true, features = ["full"] }

[lints]
workspace = true
14 changes: 7 additions & 7 deletions fastimer-driver/README.md → fastimer-core/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Fastimer Driver
# Fastimer Core API

[![Crates.io][crates-badge]][crates-url]
[![Documentation][docs-badge]][docs-url]
[![MSRV 1.85][msrv-badge]](https://www.whatrustisit.com)

[crates-badge]: https://img.shields.io/crates/v/fastimer-driver.svg
[crates-url]: https://crates.io/crates/fastimer-driver
[docs-badge]: https://docs.rs/fastimer-driver/badge.svg
[crates-badge]: https://img.shields.io/crates/v/fastimer-core.svg
[crates-url]: https://crates.io/crates/fastimer-core
[docs-badge]: https://docs.rs/fastimer-core/badge.svg
[msrv-badge]: https://img.shields.io/badge/MSRV-1.85-green?logo=rust
[docs-url]: https://docs.rs/fastimer-driver
[docs-url]: https://docs.rs/fastimer-core

## Overview

This crate implements a timer driver that can work with any async runtime scheduler.
This crate provides core APIs.

## Documentation

Read the online documents at https://docs.rs/fastimer-driver.
Read the online documents at https://docs.rs/fastimer-core.

## Minimum Supported Rust Version (MSRV)

Expand Down
69 changes: 69 additions & 0 deletions fastimer-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2024 FastLabs Developers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Fastimer Core APIs
//!
//! Core traits:
//!
//! * [`MakeDelay`]: a trait for creating delay futures.
//! * [`Spawn`]: a trait for spawning futures, this is useful for scheduling tasks.
//!
//! Utility functions:
//!
//! * [`far_future`]: create a far future instant.
//! * [`make_instant_from`]: create an instant from the given instant and a duration.
//! * [`make_instant_from_now`]: create an instant from [`Instant::now`] and a duration.

use std::future::Future;
use std::time::Duration;
use std::time::Instant;

/// Create a far future instant.
pub fn far_future() -> Instant {
// Roughly 30 years from now.
// API does not provide a way to obtain max `Instant`
// or convert specific date in the future to instant.
// 1000 years overflows on macOS, 100 years overflows on FreeBSD.
Instant::now() + Duration::from_secs(86400 * 365 * 30)
}

/// Create an instant from the given instant and a duration.
pub fn make_instant_from(now: Instant, dur: Duration) -> Instant {
now.checked_add(dur).unwrap_or_else(far_future)
}

/// Create an instant from [`Instant::now`] and a duration.
pub fn make_instant_from_now(dur: Duration) -> Instant {
make_instant_from(Instant::now(), dur)
}

/// A trait for creating delay futures.
pub trait MakeDelay {
/// The future returned by the `delay`/`delay_until` method.
type Delay: Future<Output = ()> + Send;

/// Create a future that completes at the specified instant.
fn delay_until(&self, at: Instant) -> Self::Delay;

/// Create a future that completes after the specified duration.
fn delay(&self, duration: Duration) -> Self::Delay {
self.delay_until(make_instant_from_now(duration))
}
}

/// A trait for spawning futures.
pub trait Spawn {
/// Spawn a future and return a cancellable future.
fn spawn<F: Future<Output = ()> + Send + 'static>(&self, future: F);
}
105 changes: 0 additions & 105 deletions fastimer-driver/src/heap.rs

This file was deleted.

Loading
Loading