1#![deny(unsafe_code, unsafe_op_in_unsafe_fn)]
2#![deny(rustdoc::broken_intra_doc_links)]
3#![doc = include_str!("../README.md")]
4
5mod allocation_pool;
78mod bounded_writer;
79mod capability;
80mod cbor;
81mod constants;
82mod declaration;
83mod diagnostics;
84mod hash;
85mod key;
86mod ledger;
87mod physical;
88mod policy;
89mod requests;
90mod runtime;
91mod schema;
92mod slot;
93mod sort;
94mod stable_cell;
95mod text;
96mod validation;
97
98#[cfg(test)]
99mod test_cbor {
100 use serde::{Serialize, de::DeserializeOwned};
101
102 pub use ciborium::Value;
103
104 pub fn to_vec<T: Serialize>(
105 value: &T,
106 ) -> Result<Vec<u8>, ciborium::ser::Error<std::io::Error>> {
107 let mut bytes = Vec::new();
108 ciborium::into_writer(value, &mut bytes)?;
109 Ok(bytes)
110 }
111
112 pub fn from_slice<T: DeserializeOwned>(
113 bytes: &[u8],
114 ) -> Result<T, ciborium::de::Error<std::io::Error>> {
115 crate::cbor::from_slice_exact(bytes)
116 }
117
118 pub fn to_value<T: Serialize>(value: T) -> Result<Value, ciborium::value::Error> {
119 Value::serialized(&value)
120 }
121
122 pub fn hex_fixture(contents: &str) -> Vec<u8> {
123 let hex = contents
124 .chars()
125 .filter(|char| !char.is_whitespace())
126 .collect::<String>();
127 assert_eq!(hex.len() % 2, 0, "fixture hex must have byte pairs");
128 hex.as_bytes()
129 .as_chunks::<2>()
130 .0
131 .iter()
132 .map(|pair| {
133 let pair = std::str::from_utf8(pair).expect("fixture hex is utf8");
134 u8::from_str_radix(pair, 16).expect("fixture hex byte")
135 })
136 .collect()
137 }
138}
139
140pub use ic_stable_structures;
145
146pub use allocation_pool::{MemoryAllocationPool, MemoryAllocationPoolError, MemoryAuthority};
147pub use capability::CommittedAllocations;
148pub use constants::{
149 MAX_LEDGER_BYTES, MAX_LEDGER_NESTING, MAX_LEDGER_RECORD_BYTES, WASM_PAGE_SIZE_BYTES,
150};
151pub use declaration::{AllocationDeclaration, DeclarationSnapshot, DeclarationSnapshotError};
152pub use diagnostics::{
153 DiagnosticCheck, DiagnosticCode, DiagnosticExport, DiagnosticFailure, DiagnosticMemorySize,
154 DiagnosticRecord, DiagnosticRuntimeBinding, DiagnosticStableCell, DiagnosticStableCellStatus,
155 MemoryRuntimeDoctorReport,
156};
157pub use key::{StableKey, StableKeyError};
158pub(crate) use ledger::LedgerCommitStore;
159#[cfg(test)]
160pub(crate) use ledger::LedgerPayloadEnvelope;
161pub use ledger::{
162 AllocationLedger, AllocationRecord, AllocationReservationError, AllocationRetirement,
163 AllocationRetirementError, AllocationStageError, AllocationState,
164 LEDGER_PAYLOAD_FORMAT_VERSION, LedgerCommitError, LedgerIntegrityError,
165 LedgerPayloadEnvelopeError, RecoveredLedger,
166};
167#[cfg(test)]
168pub(crate) use physical::CommittedGenerationBytes;
169pub use physical::{CommitRecoveryError, CommitSnapshotDiagnostic};
170pub use policy::{AllocationPolicy, PolicyIdentity, PolicyIdentityError, RuntimeBootstrapPolicy};
171pub use requests::{
172 MemoryDeclarationError, MemoryRequest, SealedDeclarationFingerprint, SealedDeclarationSnapshot,
173};
174pub use runtime::{
175 AllocationBinding, BootstrapAdmission, BootstrapAdmissionError, GenericAllocationPolicy,
176 MemoryAllocation, MemoryAllocationSummary, MemoryAllocations, MemoryBindingSummary,
177 MemoryManagerConfig, MemoryManagerLayoutError, MemoryResolutionError, MemoryRuntime,
178 RecoveredAllocationMetadata, RuntimeAdoptionError, RuntimeBootstrapError,
179 RuntimeConstructionError, RuntimeDiagnosticError, RuntimeGrowError, RuntimeMemory,
180 RuntimeOpenError, RuntimeStateError, bootstrap_default_memory_manager,
181 bootstrap_default_memory_manager_with_config, bootstrap_default_memory_manager_with_policy,
182 committed_allocations, default_memory_manager_commit_recovery_diagnostic,
183 default_memory_manager_diagnostic_export, default_memory_manager_doctor_report,
184 default_memory_manager_doctor_report_with_policy,
185 default_memory_manager_memory_allocation_summary, default_memory_manager_memory_allocations,
186 default_memory_manager_memory_id, is_default_memory_manager_bootstrapped,
187 open_default_memory_manager_memory, verify_default_memory_manager_authority,
188};
189pub use schema::{SchemaMetadata, SchemaMetadataError};
190pub use slot::{
191 IC_MEMORY_AUTHORITY_OWNER, IC_MEMORY_LEDGER_STABLE_KEY, IC_MEMORY_STABLE_KEY_PREFIX,
192 MEMORY_MANAGER_GOVERNANCE_MAX_ID, MEMORY_MANAGER_INVALID_ID, MEMORY_MANAGER_LEDGER_ID,
193 MEMORY_MANAGER_MAX_ID, MEMORY_MANAGER_MIN_ID, MemoryManagerIdRange, MemoryManagerRangeError,
194 MemoryManagerSlot, MemoryManagerSlotError, is_ic_memory_stable_key,
195 memory_manager_governance_range, validate_memory_manager_id,
196};
197pub use stable_cell::{
198 STABLE_CELL_HEADER_SIZE, STABLE_CELL_LAYOUT_VERSION, STABLE_CELL_MAGIC,
199 STABLE_CELL_VALUE_OFFSET, StableCellLedgerError, StableCellLedgerRecord,
200 StableCellPayloadError, decode_stable_cell_ledger_record,
201 decode_stable_cell_ledger_record_from_memory, decode_stable_cell_payload,
202};
203pub use validation::AllocationValidationError;
204#[cfg(test)]
205pub(crate) use validation::validate_allocations;
206
207#[cfg(test)]
208mod allocation_measurements_tests;
209
210#[cfg(feature = "test-support")]
211pub mod testing;