Skip to main content

canic_core/api/
memory.rs

1//! Module: api::memory
2//!
3//! Responsibility: public memory-query facade for endpoint callers.
4//! Does not own: memory accounting, stable-memory layout, or ledger updates.
5//! Boundary: maps memory workflow errors into public API errors.
6
7use crate::{
8    dto::{
9        error::Error,
10        memory::{MemoryAllocationsResponse, MemoryLedgerResponse},
11    },
12    workflow::memory::query::MemoryQuery as MemoryQueryWorkflow,
13};
14
15///
16/// MemoryQuery
17///
18/// Thin endpoint-facing facade for memory ledger queries.
19///
20
21pub struct MemoryQuery;
22
23impl MemoryQuery {
24    /// Return bounded current allocation extents without opening stable stores.
25    pub fn allocations() -> Result<MemoryAllocationsResponse, Error> {
26        MemoryQueryWorkflow::allocations().map_err(Error::from)
27    }
28
29    /// Return the current memory ledger snapshot.
30    pub fn ledger() -> Result<MemoryLedgerResponse, Error> {
31        MemoryQueryWorkflow::ledger().map_err(Error::from)
32    }
33}