use std::{error, fmt};
#[derive(Debug)]
pub enum StableMemoryError {
OutOfMemory,
}
impl fmt::Display for StableMemoryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::OutOfMemory => f.write_str("Out of memory"),
}
}
}
impl error::Error for StableMemoryError {}
pub fn stable_grow(new_pages: u64) -> Result<u64, StableMemoryError> {
match ic0::stable64_grow(new_pages) {
u64::MAX => Err(StableMemoryError::OutOfMemory),
pages => Ok(pages),
}
}
pub fn stable_write(offset: u64, buf: &[u8]) {
ic0::stable64_write(buf, offset);
}
pub fn stable_read(offset: u64, buf: &mut [u8]) {
ic0::stable64_read(buf, offset);
}