Expand description
Cape: Type-safe record and persistence state management
Cape provides a type-safe way to manage domain objects with persistence state tracking. Records wrap domain objects with metadata, relations, and track their persistence state at the type level to prevent common database synchronization errors.
§Core Concepts
- Record<T, R, S, K>: Wraps a domain object
Twith relationsR, persistence stateS, and key typeK - Persistence States: Type-level tracking of whether records are new
(
N) or stored (S) - Inner Trait: Marker trait for types that can be stored in records
Id<K>: Optional identifier wrapper that enforces correct usage patterns- Timestamps: Creation and update time tracking (optional chrono integration)
§Example
use cape::prelude::*;
#[derive(Clone)]
struct User {
name: String,
email: String,
}
// Create a new record (type: Record<User, (), N, i64>)
let new_user: Record<User, (), N, i64> = Record::new(User {
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
});
// After saving to database, convert to stored state
// let stored_user = new_user.store(123, timestamp);
// let user_id = stored_user.id(); // Only available for stored recordsModules§
- prelude
- A prelude module for Cape
Structs§
- Id
- N
- An unstored record
- Record
- A record wraps a domain object
Twith metadata and relations. - S
- A stored record
Traits§
- Inner
- Inner
Record - Persistence
- Marker trait for persistence state of a Record