Struct ic_stable_structures::log::Log
source · pub struct Log<T: Storable, INDEX: Memory, DATA: Memory> { /* private fields */ }
Expand description
Append-only list of variable-size entries stored in stable memory.
Implementations§
source§impl<T: Storable, INDEX: Memory, DATA: Memory> Log<T, INDEX, DATA>
impl<T: Storable, INDEX: Memory, DATA: Memory> Log<T, 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 into_memories(self) -> (INDEX, DATA)
pub fn into_memories(self) -> (INDEX, DATA)
Returns the underlying memory trait objects of the log.
sourcepub fn index_size_bytes(&self) -> u64
pub fn index_size_bytes(&self) -> u64
Returns the number of index memory bytes in use.
sourcepub fn data_size_bytes(&self) -> u64
pub fn data_size_bytes(&self) -> u64
Returns the number of data memory bytes in use.
sourcepub fn log_size_bytes(&self) -> u64
pub fn log_size_bytes(&self) -> u64
Returns the total size of all logged entries in bytes.
sourcepub fn get(&self, idx: u64) -> Option<T>
pub fn get(&self, idx: u64) -> Option<T>
Returns the entry at the specified index. Returns None if the entry does not exist.
sourcepub fn read_entry(&self, idx: u64, buf: &mut Vec<u8>) -> Result<(), NoSuchEntry>
pub fn read_entry(&self, idx: u64, 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.