16 lines
626 B
Markdown
16 lines
626 B
Markdown
|
|
# td36
|
||
|
|
|
||
|
|
Time-delta identifiers: a timestamp is stored as the base36 encoding of its offset from a chosen epoch, so ids stay short, sortable and monotonically increasing.
|
||
|
|
|
||
|
|
```rust
|
||
|
|
use td36::{Td36Epoch, Td36Precision};
|
||
|
|
|
||
|
|
let epoch = Td36Epoch::new(1_700_000_000, Td36Precision::Seconds);
|
||
|
|
let id = epoch.encode(1_700_000_123).unwrap();
|
||
|
|
assert_eq!(epoch.decode_id(&id).unwrap(), 1_700_000_123);
|
||
|
|
```
|
||
|
|
|
||
|
|
`Td36Epoch::encode_epoch_marker` / `decode_epoch_marker` round-trip the epoch itself, so a stream of ids can carry the epoch it is relative to.
|
||
|
|
|
||
|
|
No dependencies. `cargo test` covers epoch round-tripping and the before-epoch guard.
|