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§

Creates a new empty growable stable log backed by the memory trait objects, overwriting the previous contents.

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.

Returns the underlying memory trait objects of the log.

Returns true iff this log does not have any entries.

Returns the number of index memory bytes in use.

Returns the number of data memory bytes in use.

Returns the total size of all logged entries in bytes.

Returns the number of entries in the log.

Returns the entry at the specified index. Returns None if the entry does not exist.

Returns an iterator over log entries.

source

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.

Appends a new entry to the log. If successful, returns the index of the entry.

POST-CONDITION: Ok(idx) = log.append(E) ⇒ log.get(idx) = Some(E)

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.