Skip to main content

Crate reliakit_core

Crate reliakit_core 

Source
Expand description

Shared building blocks for the Reliakit workspace.

Reliakit’s time-driven resilience crates (reliakit-circuit, reliakit-ratelimit, reliakit-timeout) are clock-agnostic: you pass the current time in as a u64 tick in any monotonic unit you choose. This crate provides the small piece they have in common — a Clock trait and a couple of ready-made clocks — so you do not have to hand-roll one. Each of those crates has an optional core feature that adds *_now(clock) methods backed by this trait. (reliakit-backoff computes delays from an attempt number and does not read a clock.)

  • ManualClock — a settable clock for deterministic tests; no_std.
  • MonotonicClock — wall-free monotonic milliseconds (requires std).

The crate has no dependencies and forbids unsafe code. The Clock trait and ManualClock are available on no_std; MonotonicClock needs the default std feature.

§Example

use reliakit_core::{Clock, ManualClock};

let clock = ManualClock::new(0);
assert_eq!(clock.now(), 0);
clock.advance(250);
assert_eq!(clock.now(), 250);

// Feed `clock.now()` into any clock-agnostic Reliakit policy.
fn elapsed_since<C: Clock>(clock: &C, start: u64) -> u64 {
    clock.now().saturating_sub(start)
}
assert_eq!(elapsed_since(&clock, 100), 150);

Structs§

ManualClock
A clock whose time is set explicitly, for deterministic tests.
MonotonicClock
A monotonic clock measuring milliseconds since it was created.

Traits§

Clock
A source of monotonic time, expressed as a u64 tick.