foundation capa

foundation-uuid7

Time-ordered identifiers: sorting the key sorts the rows, including for a backfill where the only evidence of order is a sequence number

Time-ordered identifiers: sorting the key sorts the rows, including for a backfill where the only evidence of order is a sequence number

Tier—
Roleunclassified (baselined)
Pathcrates/foundation/uuid7
Edition2021
Targetsfoundation_uuid7
Public items5 across 0 modules
Tests12

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`

ItemWhat 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::UuidOne 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) -> i64A 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)
Locationcrates/foundation/uuid7
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
uuid^1v4, v7, serde, js, v7noalways

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

KindNameSource
libfoundation_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

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone 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.

1 workspace crate depends on this one: tools-migration-ledger.

Verification

KindCount
Unit tests12
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root502

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc55
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 5
    "No rustdoc detected" : 0

Metrics

MetricValue
Rust source files1
Source lines215
Code lines131
Public API items5
Public modules0
Tests12
Examples0
Cargo features0
Direct runtime dependencies1
Workspace reverse dependencies1
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.

Todas las foundation · Manual