Struct ic_stable_structures::log::Log
source · Expand description
Append-only list of variable-size entries stored in stable memory.
Implementations
sourceimpl<INDEX: Memory, DATA: Memory> Log<INDEX, DATA>
impl<INDEX: Memory, DATA: Memory> Log<INDEX, DATA>
sourcepub fn new(index_memory: INDEX, data_memory: DATA) -> Self
pub fn new(index_memory: INDEX, data_memory: DATA) -> Self
Creates a new empty growable stable log backed by the memory trait objects, overwriting the previous contents.
sourcepub fn init(index_memory: INDEX, data_memory: DATA) -> Result<Self, InitError>
pub fn init(index_memory: INDEX, data_memory: DATA) -> Result<Self, InitError>
Initializes the log based on the contents of the provided memory trait objects. If the memory trait objects already contain a stable log, this function recovers it from the stable memory. Otherwise, this function allocates a new empty log.
sourcepub fn forget(self) -> (INDEX, DATA)
pub fn forget(self) -> (INDEX, DATA)
Returns the underlying memory trait objects of the log.
sourcepub fn index_size_bytes(&self) -> usize
pub fn index_size_bytes(&self) -> usize
Returns the number of index memory bytes in use.
sourcepub fn data_size_bytes(&self) -> usize
pub fn data_size_bytes(&self) -> usize
Returns the number of data memory bytes in use.
sourcepub fn log_size_bytes(&self) -> usize
pub fn log_size_bytes(&self) -> usize
Returns the total size of all logged entries in bytes.
sourcepub fn get(&self, idx: usize) -> Option<Vec<u8>>
pub fn get(&self, idx: usize) -> Option<Vec<u8>>
Returns the entry at the specified index. Returns None if the entry does not exist.
sourcepub fn read_entry(&self, idx: usize, buf: &mut Vec<u8>) -> Result<(), NoSuchEntry>
pub fn read_entry(&self, idx: usize, buf: &mut Vec<u8>) -> Result<(), NoSuchEntry>
Reads the contents of the entry with the specified index into a byte vector.
NOTE: if the entry exists, this function resizes buf
to match the entry size.
NOTE: this function returns a Result to make the compiler emit a warning if the caller ignores the result.