foundation tier

foundation-singleton

Singleton pattern for single-row configuration tables

Singleton pattern for single-row configuration tables

Tierfoundation
Roleunclassified (baselined)
Pathcrates/foundation/singleton
Edition2021
Targetsfoundation_singleton
Public items0 across 0 modules
Tests28

What it is for

# foundation-singleton

Singleton pattern for single-row configuration tables.

Singletons ensure exactly one row exists per type, with:

Example

use foundation_singleton::{Singleton, SingletonError};

struct SiteSettings {
id: i32,
site_name: String,
maintenance_mode: bool,
}

impl Singleton for SiteSettings {
fn id(&self) -> i32 {
self.id
}
}

let settings = SiteSettings {
id: 1,
site_name: "My Site".to_string(),
maintenance_mode: false,
};

// Singleton ID is always 1
assert_eq!(settings.id(), 1);
assert!(settings.is_valid_singleton());

// Deletion is not allowed
assert!(settings.delete().is_err());

Capabilities

No public items.

How to use it

From this crate's own rustdoc:

use foundation_singleton::{Singleton, SingletonError};

struct SiteSettings {
    id: i32,
    site_name: String,
    maintenance_mode: bool,
}

impl Singleton for SiteSettings {
    fn id(&self) -> i32 {
        self.id
    }
}

let settings = SiteSettings {
    id: 1,
    site_name: "My Site".to_string(),
    maintenance_mode: false,
};

// Singleton ID is always 1
assert_eq!(settings.id(), 1);
assert!(settings.is_valid_singleton());

// Deletion is not allowed
assert!(settings.delete().is_err());

Module structure

No public modules: the crate root is its whole surface.

Public surface

No public items.

Re-exports. Exported here, defined elsewhere.

ExportDefined in
{EnvFallback,Singleton}traits::{EnvFallback,Singleton}
{SingletonError,ValueSource}error::{SingletonError,ValueSource}

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)
Locationcrates/foundation/singleton
Vocabulary in force (lexicon)current

Dependencies

Runtime, in this workspace.

CrateTierOptionalOnly on
`foundation-basemodels`foundationnoalways

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
sqlx^0.8runtime-tokio, postgres, chrono, uuid, jsonnoalways
thiserror^2noalways
tokio^1fullnoalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio-test^0.4noalways

Build. None.

Depended on by. 1 workspace crate.

Signal flow — what reaches this crate, and what it reaches.

flowchart LR
  n_application_singleton["application-singleton"] -->|uses| SELF
  SELF["foundation-singleton"]
  SELF -->|runtime| n_foundation_basemodels["foundation-basemodels"]
  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_singleton`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 runtimeyes
database accessyes
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: application-singleton.

Verification

KindCount
Unit tests28
Integration tests0
Examples0
Doctests1

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc00
Public modules with a //! block00

Metrics

MetricValue
Rust source files3
Source lines581
Code lines315
Public API items0
Public modules0
Tests28
Examples0
Cargo features0
Direct runtime dependencies4
Workspace reverse dependencies1
pie showData
    title Rust source composition
    "Code" : 315
    "Blank or comment" : 266

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.

All foundation · Manual