Gapless sequential ID generation with human-readable formatting
| Tier | foundation |
| Role | unclassified (baselined) |
| Path | crates/foundation/sequence |
| Edition | 2021 |
| Targets | foundation_sequence |
| Public items | 0 across 0 modules |
| Tests | 36 |
What it is for
# foundation-sequence
Gapless sequential ID generation with human-readable formatting.
Overview
This crate provides:
- Gapless sequences: Each value is returned exactly once (no gaps from rollbacks)
- Named sequences: Multiple independent sequence counters
- Human-readable formatting: Format patterns like "INV-2024-0001"
- Temporal sequences: Sequences that reset by year, month, or day
- Reset/looping: Sequences that cycle back to initial value
Example
use foundation_sequence::{Sequence, SequenceFormat, TemporalSequence, ResetPeriod};
// Basic sequence
let mut seq = Sequence::new("invoices");
assert_eq!(seq.next(), 1);
assert_eq!(seq.next(), 2);
// With formatting
let fmt = SequenceFormat::new("{prefix}-{value:05}").with_prefix("INV");
assert_eq!(fmt.format(42), "INV-00042");
// Temporal sequence (resets yearly)
let mut yearly = TemporalSequence::new("invoices", ResetPeriod::Yearly)
.with_format("{prefix}-{year}-{value:05}")
.with_prefix("INV");
let result = yearly.next();
// Returns: SequenceValue { value: 1, formatted: "INV-2026-00001", ... }
Capabilities
No public items.
How to use it
From this crate's own rustdoc:
use foundation_sequence::{Sequence, SequenceFormat, TemporalSequence, ResetPeriod};
// Basic sequence
let mut seq = Sequence::new("invoices");
assert_eq!(seq.next(), 1);
assert_eq!(seq.next(), 2);
// With formatting
let fmt = SequenceFormat::new("{prefix}-{value:05}").with_prefix("INV");
assert_eq!(fmt.format(42), "INV-00042");
// Temporal sequence (resets yearly)
let mut yearly = TemporalSequence::new("invoices", ResetPeriod::Yearly)
.with_format("{prefix}-{year}-{value:05}")
.with_prefix("INV");
let result = yearly.next();
// Returns: SequenceValue { value: 1, formatted: "INV-2026-00001", ... }
Module structure
No public modules: the crate root is its whole surface.
Public surface
No public items.
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
Sequence | sequence::Sequence |
SequenceError | error::SequenceError |
SequenceFormat | format::SequenceFormat |
{ResetPeriod,SequenceValue,TemporalSequence} | temporal::{ResetPeriod,SequenceValue,TemporalSequence} |
Boundary
Depends on no other workspace tier.
Shares tier foundation with 27 other crates: foundation-audit-log, foundation-basemodels, foundation-bounded-io, foundation-conversation-closure, foundation-crypto-sign, foundation-decisioning, foundation-encounter-vocabulary, foundation-fs-metadata, … (27 total).
_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) | foundation |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/foundation/sequence |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. Nothing in this workspace.
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_sequence | `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
No workspace crate depends on this one.
Verification
| Kind | Count |
|---|---|
| Unit tests | 36 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 1 |
What the tests establish, by name:
test_format_default—src/format.rstest_format_serialization—src/format.rstest_replace_value_pattern_multiple—src/format.rstest_fill_order_numbers_scuba—src/lib.rstest_format_complex_pattern—src/lib.rstest_format_literal_text—src/lib.rstest_format_no_placeholders—src/lib.rstest_format_value_only—src/lib.rstest_format_value_padded—src/lib.rstest_format_with_day—src/lib.rstest_format_with_month—src/lib.rstest_format_with_prefix—src/lib.rstest_format_with_year—src/lib.rstest_format_with_year_short—src/lib.rstest_invoice_workflow—src/lib.rstest_order_number_workflow—src/lib.rstest_sequence_error_display—src/lib.rstest_sequence_new—src/lib.rstest_sequence_next_increments—src/lib.rstest_sequence_peek—src/lib.rstest_sequence_reset—src/lib.rstest_sequence_with_initial—src/lib.rstest_sequence_with_reset_loops—src/lib.rstest_temporal_daily_reset—src/lib.rstest_temporal_daily_sequence_name—src/lib.rstest_temporal_monthly_reset—src/lib.rstest_temporal_monthly_sequence_name—src/lib.rstest_temporal_sequence_next—src/lib.rstest_temporal_sequence_next_for_date—src/lib.rstest_temporal_yearly_sequence_name—src/lib.rs- _… 6 more_
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 0 | 0 |
Public modules with a //! block | 0 | 0 |
Metrics
| Metric | Value |
|---|---|
| Rust source files | 5 |
| Source lines | 1035 |
| Code lines | 640 |
| Public API items | 0 |
| Public modules | 0 |
| Tests | 36 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 4 |
| Workspace reverse dependencies | 0 |
pie showData
title Rust source composition
"Code" : 640
"Blank or comment" : 395
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.