Foundation traits for rust-framework-workspace: UUID primary keys, timestamps, and soft delete
| Tier | foundation |
| Role | unclassified (baselined) |
| Path | crates/foundation/basemodels |
| Edition | 2021 |
| Targets | foundation_basemodels |
| Public items | 2 across 0 modules |
| Tests | 43 |
What it is for
# foundation-basemodels
Foundation traits for rust-framework-workspace: UUID primary keys, timestamps, and soft delete.
All domain models in the rust-framework-workspace ecosystem must implement these traits:
HasId- UUID primary keyTimestamped-created_at/updated_attrackingSoftDeletable- soft delete withdeleted_at
Example
use foundation_basemodels::{HasId, Timestamped, SoftDeletable};
use uuid::Uuid;
use chrono::{DateTime, Utc};
struct Person {
id: Uuid,
name: String,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
deleted_at: Option<DateTime<Utc>>,
}
impl HasId for Person {
fn id(&self) -> Uuid { self.id }
}
impl Timestamped for Person {
fn created_at(&self) -> DateTime<Utc> { self.created_at }
fn updated_at(&self) -> DateTime<Utc> { self.updated_at }
}
impl SoftDeletable for Person {
fn deleted_at(&self) -> Option<DateTime<Utc>> { self.deleted_at }
}
Capabilities
Id
# foundation-basemodels
| Item |
|---|
pub type Id: Uuid |
Timestamp
# foundation-basemodels
| Item |
|---|
pub type Timestamp: DateTime <Utc> |
How to use it
From this crate's own rustdoc:
use foundation_basemodels::{HasId, Timestamped, SoftDeletable};
use uuid::Uuid;
use chrono::{DateTime, Utc};
struct Person {
id: Uuid,
name: String,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
deleted_at: Option<DateTime<Utc>>,
}
impl HasId for Person {
fn id(&self) -> Uuid { self.id }
}
impl Timestamped for Person {
fn created_at(&self) -> DateTime<Utc> { self.created_at }
fn updated_at(&self) -> DateTime<Utc> { self.updated_at }
}
impl SoftDeletable for Person {
fn deleted_at(&self) -> Option<DateTime<Utc>> { self.deleted_at }
}
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub type Id: Uuid | Type alias for the standard ID type (UUID) |
pub type Timestamp: DateTime <Utc> | Type alias for the standard timestamp type |
Re-exports. Exported here, defined elsewhere.
| Export | Defined in |
|---|---|
BaseModelError | error::BaseModelError |
Uuid | uuid::Uuid |
{DateTime,Utc} | chrono::{DateTime,Utc} |
{HasId,SoftDeletable,Timestamped} | traits::{HasId,SoftDeletable,Timestamped} |
{NilUuidError,NonNilUuid,NonNilUuidFromStrError} | non_nil_uuid::{NilUuidError,NonNilUuid,NonNilUuidFromStrError} |
Boundary
Depends on no other workspace tier.
Shares tier foundation with 27 other crates: foundation-audit-log, foundation-bounded-io, foundation-conversation-closure, foundation-crypto-sign, foundation-decisioning, foundation-encounter-vocabulary, foundation-fs-metadata, foundation-i18n, … (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/basemodels |
| 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 |
sqlx | ^0.8 | runtime-tokio, postgres, chrono, uuid, json | yes | always |
thiserror | ^2 | — | no | always |
uuid | ^1 | v4, v7, serde, js | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
serde_json | ^1 | — | no | always |
tokio | ^1 | full | no | always |
tokio-test | ^0.4 | — | no | always |
Build. None.
Depended on by. 59 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR consumers["59 consumer crates"] -->|uses| SELF SELF["foundation-basemodels"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
| Feature | Enables | On by default |
|---|---|---|
default | — | yes |
sqlx | dep:sqlx | no |
flowchart LR n_default["default"] n_sqlx["sqlx"] --> n_dep_sqlx["dep:sqlx"]
Targets
| Kind | Name | Source |
|---|---|---|
| lib | foundation_basemodels | `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 | yes |
| 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
59 workspace crates depend on this one: content-assets, content-calendar, content-calendar-recurrence, content-cms, content-directory-listing, content-notes, domain-agreements, domain-billing, domain-catalog, domain-classify, domain-comments, domain-contact, … (59 total).
Verification
| Kind | Count |
|---|---|
| Unit tests | 43 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 1 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 2 | 0 | 5 |
What the tests establish, by name:
test_base_model_error_display—src/lib.rstest_created_at_equals_updated_at_on_new—src/lib.rstest_created_at_returns_datetime—src/lib.rstest_deleted_at_none_for_active—src/lib.rstest_deleted_at_some_for_deleted—src/lib.rstest_deleted_at_timestamp_is_valid—src/lib.rstest_different_id_types_are_incompatible—src/lib.rstest_different_models_have_different_ids—src/lib.rstest_has_id_as_trait_object—src/lib.rstest_has_id_is_consistent—src/lib.rstest_has_id_returns_uuid—src/lib.rstest_is_deleted_false_for_active—src/lib.rstest_is_deleted_true_for_deleted—src/lib.rstest_newtype_id_as_uuid_ref—src/lib.rstest_newtype_id_copy_semantics—src/lib.rstest_newtype_id_derives_sqlx_type_when_feature_enabled—src/lib.rstest_newtype_id_display—src/lib.rstest_newtype_id_from_str—src/lib.rstest_newtype_id_from_str_invalid—src/lib.rstest_newtype_id_hash—src/lib.rstest_newtype_id_new_creates_valid_uuid—src/lib.rstest_newtype_id_nil—src/lib.rstest_newtype_id_roundtrip_uuid—src/lib.rstest_newtype_id_serde_roundtrip—src/lib.rstest_newtype_id_serde_transparent—src/lib.rstest_soft_deletable_as_trait_object—src/lib.rstest_timestamped_as_trait_object—src/lib.rstest_timestamps_are_consistent—src/lib.rstest_timestamps_are_utc—src/lib.rstest_updated_at_returns_datetime—src/lib.rs- _… 13 more_
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 2 | 2 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 2
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 5 |
| Source lines | 937 |
| Code lines | 497 |
| Public API items | 2 |
| Public modules | 0 |
| Tests | 43 |
| Examples | 0 |
| Cargo features | 2 |
| Direct runtime dependencies | 5 |
| Workspace reverse dependencies | 59 |
pie showData
title Public API by kind
"type alias" : 2
pie showData
title Rust source composition
"Code" : 497
"Blank or comment" : 440
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.