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>

source

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.

source

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.

source

pub fn into_memories(self) -> (INDEX, DATA)

Returns the underlying memory trait objects of the log.

source

pub fn is_empty(&self) -> bool

Returns true iff this log does not have any entries.

source

pub fn index_size_bytes(&self) -> u64

Returns the number of index memory bytes in use.

source

pub fn data_size_bytes(&self) -> u64

Returns the number of data memory bytes in use.

source

pub fn log_size_bytes(&self) -> u64

Returns the total size of all logged entries in bytes.

source

pub fn len(&self) -> u64

Returns the number of entries in the log.

source

pub fn get(&self, idx: u64) -> Option<T>

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

source

pub fn iter(&self) -> Iter<'_, T, INDEX, DATA>

Returns an iterator over log entries.

source

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.

source

pub fn append(&self, item: &T) -> Result<u64, WriteError>

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§

§

impl<T, INDEX, DATA> RefUnwindSafe for Log<T, INDEX, DATA>
where DATA: RefUnwindSafe, INDEX: RefUnwindSafe, T: RefUnwindSafe,

§

impl<T, INDEX, DATA> Send for Log<T, INDEX, DATA>
where DATA: Send, INDEX: Send, T: Send,

§

impl<T, INDEX, DATA> Sync for Log<T, INDEX, DATA>
where DATA: Sync, INDEX: Sync, T: Sync,

§

impl<T, INDEX, DATA> Unpin for Log<T, INDEX, DATA>
where DATA: Unpin, INDEX: Unpin, T: Unpin,

§

impl<T, INDEX, DATA> UnwindSafe for Log<T, INDEX, DATA>
where DATA: UnwindSafe, INDEX: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.