Struct BufferManager

Source
pub struct BufferManager<'a, V> { /* private fields */ }

Implementations§

Source§

impl<'a, V> BufferManager<'a, V>
where V: Serialize + DeserializeOwned + 'a,

Source

pub fn init( store: &mut dyn Storage, store_iface: CircularBuffer<'a, V>, capacity: u32, ) -> BufferResult<()>

Static function to initialize buffer in storage. Intended to be called during contract initialization.

Source

pub fn new( store: &dyn Storage, store_iface: CircularBuffer<'a, V>, ) -> BufferResult<Self>

Initialize buffer manager. In case buffer is not initialized it throws BufferError::BufferNotInitialized error.

Source

pub fn capacity(&self) -> u32

Returns current buffer capacity.

Source

pub fn head(&self) -> u32

Returns current buffer head.

Source

pub fn push(&mut self, value: &'a V)

Push value to precommit buffer.

Source

pub fn push_many(&mut self, values: &'a [V])

Push multiple values to precommit buffer.

Source

pub fn instant_push( &mut self, store: &mut dyn Storage, value: &'a V, ) -> BufferResult<()>

Push value to precommit buffer and commit it to storage.

Source

pub fn commit(&mut self, store: &mut dyn Storage) -> BufferResult<()>

Commit in storage current state and precommit buffer. Buffer is erased after commit.

Source

pub fn read( &self, store: &dyn Storage, indexes: impl IntoIterator<Item = impl Into<u32> + Display>, stop_if_empty: bool, ) -> BufferResult<Vec<V>>

Read values from storage by indexes. If stop_if_empty is true, reading will stop when first empty value is encountered. Otherwise, BufferError::IndexNotFound error will be thrown.

§Examples:

let values = buffer.read(&store, 0u32..=9, false).unwrap();
let values = buffer.read(&store, vec![0u32, 5, 7], false).unwrap();
let values = buffer.read(&store, (0u32..buffer.capacity()).step_by(2), false).unwrap();
Source

pub fn read_all(&self, store: &dyn Storage) -> BufferResult<Vec<V>>

Read all available values from storage.

Source

pub fn read_last(&self, store: &dyn Storage) -> BufferResult<Option<V>>

Read last saved value from storage. Returns None if buffer is empty.

Source

pub fn read_single( &self, store: &dyn Storage, index: impl Into<u32>, ) -> BufferResult<Option<V>>

Looped read. Returns None if value in buffer does not exist.

Source

pub fn clear_buffer(&self, store: &mut dyn Storage)

This operation is gas consuming. However, it might be helpful in rare cases.

Source

pub fn exists(&self, store: &dyn Storage, index: u32) -> bool

Whether index exists in buffer.

Trait Implementations§

Source§

impl<V: Debug> Debug for BufferManager<'_, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, V> Freeze for BufferManager<'a, V>

§

impl<'a, V> RefUnwindSafe for BufferManager<'a, V>
where V: RefUnwindSafe,

§

impl<'a, V> Send for BufferManager<'a, V>
where V: Send + Sync,

§

impl<'a, V> Sync for BufferManager<'a, V>
where V: Sync,

§

impl<'a, V> Unpin for BufferManager<'a, V>
where V: Unpin,

§

impl<'a, V> UnwindSafe for BufferManager<'a, V>

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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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.