Skip to content
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
23 changes: 7 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gardal"
version = "0.0.1-alpha.2"
version = "0.0.1-alpha.3"
edition = "2024"
license = "Apache-2.0 OR MIT"
authors = ["Ahmed Farghal <me@asoli.dev>"]
Expand All @@ -24,7 +24,7 @@ tokio-hrtime = { version = "0.1", optional = true }

[dev-dependencies]
gardal = { path = ".", features = ["async", "tokio", "quanta"] }
criterion = { version = "0.6", default-features = false }
criterion = { version = "0.7", default-features = false }
tokio = { version = "1", features = ["sync", "time", "test-util", "macros", "rt", "rt-multi-thread"] }
nonzero_ext = { version = "0.3" }
tokio-stream = { version = "0.1", features = ["time"] }
Expand Down
1 change: 1 addition & 0 deletions src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pub trait Clock {
/// let clock = StdClock::default();
/// let bucket = TokenBucket::with_clock(limit, clock);
/// ```
#[derive(Clone)]
pub struct StdClock {
origin: std::time::Instant,
}
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ pub use futures::RateLimitedStreamExt;
pub use limit::RateLimit;
pub use tokens::Tokens;

pub use storage::atomic::{AtomicSharedStorage, AtomicStorage};
pub use storage::local::LocalStorage;
pub use storage::padded_atomic::PaddedAtomicStorage;
pub use storage::{
TimeStorage, atomic::AtomicSharedStorage, atomic::AtomicStorage, local::LocalStorage,
padded_atomic::PaddedAtomicStorage,
};

pub(crate) mod private {
pub trait Sealed {}
}
2 changes: 1 addition & 1 deletion src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod padded_atomic;
///
/// Implementations can provide either atomic or non-atomic access to the
/// underlying timestamp depending on the desired level of concurrency.
pub trait TimeStorage {
pub trait TimeStorage: crate::private::Sealed {
/// Create a new storage policy with the provided zero time.
fn new(zero_time: f64) -> Self;
/// Load the current zero time.
Expand Down
4 changes: 4 additions & 0 deletions src/storage/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ impl Debug for AtomicF64 {
#[derive(Debug)]
pub struct AtomicStorage(AtomicF64);

impl crate::private::Sealed for AtomicStorage {}

impl TimeStorage for AtomicStorage {
fn new(zero_time: f64) -> Self {
Self(AtomicF64::new(zero_time))
Expand Down Expand Up @@ -105,6 +107,8 @@ impl TimeStorage for AtomicStorage {
#[derive(Debug, Clone)]
pub struct AtomicSharedStorage(Arc<AtomicF64>);

impl crate::private::Sealed for AtomicSharedStorage {}

impl TimeStorage for AtomicSharedStorage {
fn new(zero_time: f64) -> Self {
Self(Arc::new(AtomicF64::new(zero_time)))
Expand Down
2 changes: 2 additions & 0 deletions src/storage/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ use super::TimeStorage;
#[derive(Debug)]
pub struct LocalStorage(Cell<f64>);

impl crate::private::Sealed for LocalStorage {}

impl TimeStorage for LocalStorage {
fn new(zero_time: f64) -> Self {
Self(Cell::new(zero_time))
Expand Down
2 changes: 2 additions & 0 deletions src/storage/padded_atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use super::cache_padded::CachePadded;
/// ```
pub struct PaddedAtomicStorage(CachePadded<AtomicF64>);

impl crate::private::Sealed for PaddedAtomicStorage {}

impl TimeStorage for PaddedAtomicStorage {
fn new(zero_time: f64) -> Self {
Self(CachePadded::new(AtomicF64::new(zero_time)))
Expand Down
Loading