1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Persist and retrieve data from an abstract store.
//!
//! # Status
//!
//! Stability varies by primitive. See [README](https://github.com/commonwarexyz/monorepo#stability) for details.
#![doc(
html_logo_url = "https://commonware.xyz/imgs/rustdoc_logo.svg",
html_favicon_url = "https://commonware.xyz/favicon.ico"
)]
#![cfg_attr(not(any(feature = "std", test)), no_std)]
commonware_macros::stability_scope!(ALPHA {
extern crate alloc;
pub mod merkle;
pub use merkle::{mmb, mmr};
});
commonware_macros::stability_scope!(ALPHA, cfg(feature = "std") {
mod bitmap;
pub mod qmdb;
pub use crate::bitmap::{BitMap as AuthenticatedBitMap, MerkleizedBitMap, UnmerkleizedBitMap};
pub mod bmt;
pub mod cache;
pub mod queue;
});
commonware_macros::stability_scope!(BETA, cfg(feature = "std") {
pub mod archive;
pub mod freezer;
pub mod index;
pub mod journal;
pub mod metadata;
pub mod ordinal;
pub mod rmap;
/// A runtime context providing storage, timing, and metrics capabilities.
///
/// This is a convenience alias for the trait bound
/// `Storage + Clock + Metrics` that appears on nearly every type in this crate.
pub trait Context:
commonware_runtime::Storage + commonware_runtime::Clock + commonware_runtime::Metrics
{
}
impl<
T: commonware_runtime::Storage + commonware_runtime::Clock + commonware_runtime::Metrics,
> Context for T
{
}
/// A storage structure with capabilities to persist and recover state across restarts.
pub trait Persistable {
/// The error type returned when there is a failure from the underlying storage system.
type Error;
/// Durably persist the structure, guaranteeing the current state will survive a crash.
///
/// For a stronger guarantee that eliminates potential recovery, use [Self::sync] instead.
fn commit(&self) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send {
self.sync()
}
/// Durably persist the structure, guaranteeing the current state will survive a crash, and that
/// no recovery will be needed on startup.
///
/// This provides a stronger guarantee than [Self::commit] but may be slower.
fn sync(&self) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
/// Destroy the structure, removing all associated storage.
///
/// This method consumes the structure and deletes all persisted data, leaving behind no storage
/// artifacts. This can be used to clean up disk resources in tests.
fn destroy(self) -> impl std::future::Future<Output = Result<(), Self::Error>> + Send;
}
});
commonware_macros::stability_scope!(BETA {
pub mod translator;
});