Skip to content

ashforge-rs/ash-time

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ash-time

Distributed time primitives for Rust. ash-time is a toolkit for reasoning about order and causality across nodes — answering "did A happen before B?" without a central coordinator.

  Node A  ── stamp(write) → ts=(103ms, 0) ──────────────────────────▶
                                   │  message carries ts
                                   ▼
  Node B  ── recv(ts) → ts=(103ms, 1) ── stamp(read) → ts=(103ms, 2) ──▶

  (103ms, 0) < (103ms, 2): the read is provably after the write.

Algorithms

Hybrid Logical Clock (ash_time::hlc)

Tracks causality while staying anchored to wall time. The clock ticks with the system clock when it can, and falls back to a logical counter to break ties within the same nanosecond.

use ash_time::HlcClock;

let clock = HlcClock::new();

// stamp an outgoing message
let send_ts = clock.now().unwrap();

// advance on an incoming message — recv_ts is provably after send_ts
let recv_ts = clock.recv(send_ts).unwrap();
assert!(send_ts.happened_before(recv_ts));

See the crate docs for the full API.

Installation

cargo add ash-time

License

Licensed under the Apache License, Version 2.0.

About

Distributed time primitives for Rust.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors