icydb_core/traits/mod.rs
1//! Module: traits
2//!
3//! Responsibility: foundational kind, field metadata, and projection
4//! contracts awaiting narrower domain ownership.
5//! Does not own: entity composition, key taxonomy, runtime value conversion,
6//! visitor traversal, executor policy, or public facade DTO behavior.
7//! Boundary: remaining reusable contracts consumed throughout `icydb-core`.
8
9use crate::db::memory_runtime;
10
11// ============================================================================
12// FOUNDATIONAL KINDS
13// ============================================================================
14//
15// These traits define *where* something lives in the system,
16// not what data it contains.
17//
18
19///
20/// Path
21/// Fully-qualified schema path.
22///
23
24pub trait Path {
25 const PATH: &'static str;
26}
27
28///
29/// CanisterKind
30/// Marker for canister namespaces
31///
32
33pub trait CanisterKind: Path + 'static {
34 /// Resolve the commit slot from committed allocation authority.
35 fn commit_memory_id() -> Result<u8, ic_memory::RuntimeOpenError> {
36 memory_runtime()
37 .ok_or(ic_memory::RuntimeOpenError::NotBootstrapped)?
38 .memory_id(Self::COMMIT_STABLE_KEY)
39 }
40
41 /// Durable stable-memory allocation key for commit marker storage.
42 const COMMIT_STABLE_KEY: &'static str;
43
44 /// Resolve the startup slot from committed allocation authority.
45 fn startup_memory_id() -> Result<u8, ic_memory::RuntimeOpenError> {
46 memory_runtime()
47 .ok_or(ic_memory::RuntimeOpenError::NotBootstrapped)?
48 .memory_id(Self::STARTUP_STABLE_KEY)
49 }
50
51 /// Durable stable-memory allocation key for startup coordination state.
52 const STARTUP_STABLE_KEY: &'static str;
53
54 /// Resolve the integrity slot from committed allocation authority.
55 fn integrity_progress_memory_id() -> Result<u8, ic_memory::RuntimeOpenError> {
56 memory_runtime()
57 .ok_or(ic_memory::RuntimeOpenError::NotBootstrapped)?
58 .memory_id(Self::INTEGRITY_PROGRESS_STABLE_KEY)
59 }
60
61 /// Durable stable-memory allocation key for integrity-inspection progress.
62 const INTEGRITY_PROGRESS_STABLE_KEY: &'static str;
63}
64
65///
66/// Repr
67///
68/// Internal representation boundary for scalar wrapper types.
69///
70
71pub trait Repr {
72 type Inner;
73
74 fn repr(&self) -> Self::Inner;
75 fn from_repr(inner: Self::Inner) -> Self;
76}