<p align="center">
<img src="https://raw.githubusercontent.com/satyakwok/reliakit/main/assets/reliakit-logo.png" alt="Reliakit" width="400">
</p>
# reliakit-core
[](https://crates.io/crates/reliakit-core)
[](https://crates.io/crates/reliakit-core)
[](https://docs.rs/reliakit-core)
[](https://github.com/satyakwok/reliakit/actions/workflows/ci.yml)
[](https://codecov.io/gh/satyakwok/reliakit/tree/main/crates/reliakit-core)
[](https://github.com/satyakwok/reliakit/blob/main/LICENSE)
[](https://github.com/satyakwok/reliakit#footprint)
Shared building blocks for the Reliakit workspace.
Reliakit's resilience crates (`reliakit-backoff`, `reliakit-circuit`,
`reliakit-ratelimit`, `reliakit-timeout`) are *clock-agnostic*: you pass the
current time in as a `u64` tick in any monotonic unit. `reliakit-core` provides
the small piece they share — a `Clock` trait plus ready-made clocks — so you do
not have to hand-roll one.
The crate has no dependencies and forbids unsafe code.
## What This Crate Does
- `Clock` — a trait with a single `now(&self) -> u64`. There is a blanket impl
for `&C`, and it is object-safe (`&dyn Clock`).
- `ManualClock` — a settable clock for deterministic tests (`new`, `set`,
`advance`); uses interior mutability so every method takes `&self`. `no_std`.
- `MonotonicClock` — milliseconds since creation, backed by
`std::time::Instant`, so it never goes backwards and ignores wall-clock
adjustments. Requires the `std` feature.
## Installation
```toml
[dependencies]
reliakit-core = "1.0"
```
Disable default features for `no_std`; `ManualClock` and the `Clock` trait work
without `std`, while `MonotonicClock` needs the default `std` feature.
## Example
```rust
use reliakit_core::{Clock, ManualClock};
let clock = ManualClock::new(0);
clock.advance(250);
assert_eq!(clock.now(), 250);
// Feed `clock.now()` into any clock-agnostic Reliakit policy, e.g.
// `breaker.allow(clock.now())` or `limiter.try_acquire_one(clock.now())`.
```
## Feature flags
| `std` | yes | Enables `MonotonicClock` (real monotonic time). |
## Safety
This crate is `#![forbid(unsafe_code)]` and `no_std` (with the default `std`
feature adding `MonotonicClock`). Clock arithmetic saturates.
## Minimum Supported Rust Version
Rust `1.85` and newer. No nightly features are used.
## Status
Published to crates.io and pre-1.0. The crate is intentionally minimal — a
`Clock` trait plus two clocks — and its API may receive backward-compatible
refinements before a `1.0` release.
## License
Licensed under the MIT License. See [`LICENSE`](https://github.com/satyakwok/reliakit/blob/main/LICENSE).