grafos_leasekit/
lib.rs

1//! Lease renewal and TTL budgeting for grafOS.
2//!
3//! This crate provides poll-driven lease renewal infrastructure. The core
4//! design is timer-free: callers drive progress by calling
5//! [`RenewalManager::tick`] with the current unix timestamp. This makes
6//! the crate compatible with `no_std`, WASM, and bare-metal environments.
7//!
8//! # Core types
9//!
10//! | Type | Purpose |
11//! |------|---------|
12//! | [`RenewableLease`] | Trait abstracting lease renewal across resource types |
13//! | [`RenewalPolicy`] | Configures when to renew (threshold, jitter, backoff) |
14//! | [`Backoff`] | Deterministic exponential backoff with configurable cap |
15//! | [`RenewalManager`] | Manages multiple leases and drives renewals via `tick()` |
16//! | [`LeaseHandle`] | Workload-facing handle for observing revoke state |
17//!
18//! # Adapters
19//!
20//! Adapters for all grafos-std lease types are provided in the [`adapter`]
21//! module: [`MemLeaseAdapter`], [`BlockLeaseAdapter`], [`CpuLeaseAdapter`],
22//! [`GpuLeaseAdapter`], [`NetLeaseAdapter`].
23//!
24//! # Quick start
25//!
26//! ```rust
27//! use grafos_leasekit::{RenewalManager, RenewalPolicy};
28//!
29//! let mut mgr = RenewalManager::new();
30//! let policy = RenewalPolicy::default();
31//!
32//! // Register a lease (id, expiry, policy)
33//! mgr.register(1, 1100, policy);
34//!
35//! // Drive renewals — call tick() periodically with current time
36//! let summary = mgr.tick(1080); // 80% through TTL
37//! ```
38//!
39//! # Feature flags
40//!
41//! | Feature | Default | Effect |
42//! |---------|---------|--------|
43//! | `std` | Yes | Enables `std` in grafos-std |
44//! | `observe` | No | Enables `grafos-observe` metrics and events |
45
46#![cfg_attr(not(feature = "std"), no_std)]
47
48extern crate alloc;
49
50pub mod adapter;
51mod backoff;
52mod manager;
53mod policy;
54mod renewable;
55
56pub use backoff::Backoff;
57pub use manager::{
58    LeaseHandle, LeaseRevokeTransitionError, RenewalManager, RenewalSummary, RevokeState,
59};
60pub use policy::RenewalPolicy;
61pub use renewable::{LeaseStatus, RenewableLease};
62
63pub use adapter::{
64    BlockLeaseAdapter, CpuLeaseAdapter, GpuLeaseAdapter, MemLeaseAdapter, NetLeaseAdapter,
65};