Skip to main content

StorageRead

Trait StorageRead 

Source
pub trait StorageRead<Type: Mappable>: StorageInspect<Type> + StorageSize<Type> {
    // Required methods
    fn read_exact(
        &self,
        key: &Type::Key,
        offset: usize,
        buf: &mut [u8],
    ) -> Result<Result<usize, StorageReadError>, Self::Error>;
    fn read_zerofill(
        &self,
        key: &Type::Key,
        offset: usize,
        buf: &mut [u8],
    ) -> Result<Result<usize, StorageReadError>, Self::Error>;
    fn read_alloc(
        &self,
        key: &Type::Key,
    ) -> Result<Option<Vec<u8>>, Self::Error>;
}
Expand description

Base storage trait for Fuel infrastructure.

Allows reading the raw bytes of the value stored at a given key into a provided buffer.

This trait should skip any deserialization and simply copy the raw bytes.

Required Methods§

Source

fn read_exact( &self, key: &Type::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Read the value stored at the given key into the provided buffer if the value exists. Errors if the buffer cannot be filled completely, or if attempting to read past the end of the value.

Does not perform any deserialization.

Returns Ok(Ok(length)) if the value does exist, where the length is the total length of the value stored at the key.

Note that inner error Ok(Err(_)) is used to communicate errors that the called should be able to handle, not ones caused by underlying IO.

Source

fn read_zerofill( &self, key: &Type::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Read the value stored at the given key into the provided buffer if the value exists. If the buffer cannot be filled completely, the remaining bytes are filled with zeros.

Does not perform any deserialization.

Returns Ok(Ok(length)) if the value does exist, where the length is the total length of the value stored at the key.

Note that inner error Ok(Err(_)) is used to communicate errors that the called should be able to handle, not ones caused by underlying IO.

Source

fn read_alloc(&self, key: &Type::Key) -> Result<Option<Vec<u8>>, Self::Error>

Same as read but allocates a new buffer and returns it.

Checks the size of the value and allocates a buffer of that size.

Implementations on Foreign Types§

Source§

impl<T: StorageRead<Type> + StorageSize<Type> + ?Sized, Type: Mappable> StorageRead<Type> for &T

Source§

fn read_exact( &self, key: &<Type as Mappable>::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Source§

fn read_zerofill( &self, key: &<Type as Mappable>::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Source§

fn read_alloc( &self, key: &<Type as Mappable>::Key, ) -> Result<Option<Vec<u8>>, Self::Error>

Source§

impl<T: StorageRead<Type> + StorageSize<Type> + ?Sized, Type: Mappable> StorageRead<Type> for &mut T

Source§

fn read_exact( &self, key: &<Type as Mappable>::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Source§

fn read_zerofill( &self, key: &<Type as Mappable>::Key, offset: usize, buf: &mut [u8], ) -> Result<Result<usize, StorageReadError>, Self::Error>

Source§

fn read_alloc( &self, key: &<Type as Mappable>::Key, ) -> Result<Option<Vec<u8>>, Self::Error>

Implementors§