Time-ordered identifiers: sorting the key sorts the rows, including for a backfill where the only evidence of order is a sequence number
| Tier | — |
| Role | unclassified (baselined) |
| Path | crates/foundation/uuid7 |
| Edition | 2021 |
| Targets | foundation_uuid7 |
| Public items | 5 across 0 modules |
| Tests | 12 |
What it is for
Time-ordered identifiers, and the ordering rule a backfill needs.
A version 7 identifier carries its timestamp in the high bits, so sorting the identifiers sorts the rows. That is the whole reason to prefer one over a random identifier: the order needs no second column to hold it.
# What this crate adds over Uuid::now_v7
now_v7 answers "an id, now". Two of them taken in the same millisecond do not reliably compare in the order they were taken, and neither can be taken for a row that was written last year.
Backfilling an existing sequence needs both: identifiers for rows that already happened, in an order that is already decided, where the evidence of when is partial. ordered_millis turns partial evidence into a strictly increasing sequence, and ids_for turns that into identifiers.
# The rule
Use the recorded time when it moves forward. Where it does not — two rows in the same millisecond, or a clock that went backwards, or no record at all — take the next millisecond after the previous row. The sequence is the authority on order; a timestamp is evidence about it.
Written for the migration ledger (2026-09-10), where the recorded times stopped part way through and the rest had to be ordered by their sequence number alone. Nothing here knows about migrations.
Capabilities
crate root
Time-ordered identifiers, and the ordering rule a backfill needs.
| Item |
|---|
fn ordered_millis(known : & Option <i64>, floor : i64) -> Vec <i64> |
fn ids_for(millis : & i64) -> Vec <uuid::Uuid> |
fn id_at(millis : i64) -> uuid::Uuid |
fn backfill_ids(known : & Option <i64>, floor : i64) -> Vec <uuid::Uuid> |
fn floor_before_now(count : usize) -> i64 |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
fn ordered_millis(known : & Option <i64>, floor : i64) -> Vec <i64> | Milliseconds since the unix epoch for each position, strictly increasing |
fn ids_for(millis : & i64) -> Vec <uuid::Uuid> | A version 7 identifier per millisecond, in the order given |
fn id_at(millis : i64) -> uuid::Uuid | One identifier for one millisecond. |
fn backfill_ids(known : & Option <i64>, floor : i64) -> Vec <uuid::Uuid> | Identifiers for a run of positions whose order is known and whose times are partly or wholly unknown — the backfill case, in one call. |
fn floor_before_now(count : usize) -> i64 | A floor count milliseconds before now, so a backfilled run lands just before the present instead of in the future |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
No other crate shares its tier.
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | — |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/foundation/uuid7 |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
uuid | ^1 | v4, v7, serde, js, v7 | no | always |
Development. None.
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_tools_migration_ledger["tools-migration-ledger"] -->|uses| SELF SELF["foundation-uuid7"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | foundation_uuid7 | `src/lib.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
1 workspace crate depends on this one: tools-migration-ledger.
Verification
| Kind | Count |
|---|---|
| Unit tests | 12 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 5 | 0 | 2 |
What the tests establish, by name:
a_backwards_time_does_not_reorder_the_run—src/lib.rsa_known_time_after_unknown_ones_is_honoured—src/lib.rsa_repeated_time_moves_forward_rather_than_colliding—src/lib.rsa_time_before_the_epoch_clamps_instead_of_wrapping—src/lib.rsan_empty_run_produces_nothing—src/lib.rsevery_identifier_states_version_seven—src/lib.rsidentifiers_do_not_repeat—src/lib.rsidentifiers_sort_in_the_order_they_were_assigned—src/lib.rspositions_with_no_record_follow_from_the_floor—src/lib.rsrecorded_times_are_kept_when_they_advance—src/lib.rsthe_floor_sits_before_now_by_one_millisecond_per_row—src/lib.rsthe_ordering_rule_is_what_separates_rows_not_the_identifier—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 5 | 5 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 5
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 215 |
| Code lines | 131 |
| Public API items | 5 |
| Public modules | 0 |
| Tests | 12 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 1 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"function" : 5
pie showData
title Rust source composition
"Code" : 131
"Blank or comment" : 84
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.