pub struct Storage {
pub api: Box<dyn StorageAPI>,
}Expand description
Storage object
Fields
api: Box<dyn StorageAPI>APIs the provided by th host
Implementations
sourceimpl Storage
impl Storage
sourcepub fn new(api: Box<dyn StorageAPI>) -> Self
pub fn new(api: Box<dyn StorageAPI>) -> Self
creates a new instance of storage
sourcepub fn read_u8(&self, offset: u32) -> Result<u8, Error>
pub fn read_u8(&self, offset: u32) -> Result<u8, Error>
reads 1 byte(s) from storage file at the given offset and converts it to u8.
sourcepub fn write_u8(&self, offset: u32, value: u8) -> Result<(), Error>
pub fn write_u8(&self, offset: u32, value: u8) -> Result<(), Error>
converts u8 to 1 byte(s) and writes into storage file at the given offset.
sourcepub fn read_u16(&self, offset: u32) -> Result<u16, Error>
pub fn read_u16(&self, offset: u32) -> Result<u16, Error>
reads 2 byte(s) from storage file at the given offset and converts it to u16.
sourcepub fn write_u16(&self, offset: u32, value: u16) -> Result<(), Error>
pub fn write_u16(&self, offset: u32, value: u16) -> Result<(), Error>
converts u16 to 2 byte(s) and writes into storage file at the given offset.
sourcepub fn read_u32(&self, offset: u32) -> Result<u32, Error>
pub fn read_u32(&self, offset: u32) -> Result<u32, Error>
reads 4 byte(s) from storage file at the given offset and converts it to u32.
sourcepub fn write_u32(&self, offset: u32, value: u32) -> Result<(), Error>
pub fn write_u32(&self, offset: u32, value: u32) -> Result<(), Error>
converts u32 to 4 byte(s) and writes into storage file at the given offset.
sourcepub fn read_u64(&self, offset: u32) -> Result<u64, Error>
pub fn read_u64(&self, offset: u32) -> Result<u64, Error>
reads 8 byte(s) from storage file at the given offset and converts it to u64.
sourcepub fn write_u64(&self, offset: u32, value: u64) -> Result<(), Error>
pub fn write_u64(&self, offset: u32, value: u64) -> Result<(), Error>
converts u64 to 8 byte(s) and writes into storage file at the given offset.
sourcepub fn read_i8(&self, offset: u32) -> Result<i8, Error>
pub fn read_i8(&self, offset: u32) -> Result<i8, Error>
reads 1 byte(s) from storage file at the given offset and converts it to i8.
sourcepub fn write_i8(&self, offset: u32, value: i8) -> Result<(), Error>
pub fn write_i8(&self, offset: u32, value: i8) -> Result<(), Error>
converts i8 to 1 byte(s) and writes into storage file at the given offset.
sourcepub fn read_i16(&self, offset: u32) -> Result<i16, Error>
pub fn read_i16(&self, offset: u32) -> Result<i16, Error>
reads 2 byte(s) from storage file at the given offset and converts it to i16.
sourcepub fn write_i16(&self, offset: u32, value: i16) -> Result<(), Error>
pub fn write_i16(&self, offset: u32, value: i16) -> Result<(), Error>
converts i16 to 2 byte(s) and writes into storage file at the given offset.
sourcepub fn read_i32(&self, offset: u32) -> Result<i32, Error>
pub fn read_i32(&self, offset: u32) -> Result<i32, Error>
reads 4 byte(s) from storage file at the given offset and converts it to i32.
sourcepub fn write_i32(&self, offset: u32, value: i32) -> Result<(), Error>
pub fn write_i32(&self, offset: u32, value: i32) -> Result<(), Error>
converts i32 to 4 byte(s) and writes into storage file at the given offset.
sourcepub fn read_i64(&self, offset: u32) -> Result<i64, Error>
pub fn read_i64(&self, offset: u32) -> Result<i64, Error>
reads 8 byte(s) from storage file at the given offset and converts it to i64.
sourcepub fn write_i64(&self, offset: u32, value: i64) -> Result<(), Error>
pub fn write_i64(&self, offset: u32, value: i64) -> Result<(), Error>
converts i64 to 8 byte(s) and writes into storage file at the given offset.
sourcepub fn read_bool(&self, offset: u32) -> Result<bool, Error>
pub fn read_bool(&self, offset: u32) -> Result<bool, Error>
reads 1 byte from storage file at the given offset and converts it to bool.
sourcepub fn write_bool(&self, offset: u32, value: bool) -> Result<(), Error>
pub fn write_bool(&self, offset: u32, value: bool) -> Result<(), Error>
converts bool to 1 byte(s) and writes into storage file at the given offset.
sourcepub fn read_string(&self, offset: u32, max_len: u32) -> Result<String, Error>
pub fn read_string(&self, offset: u32, max_len: u32) -> Result<String, Error>
reads string from the storage file at the given offset.
sourcepub fn write_string(
&self,
offset: u32,
value: &str,
max_len: u32
) -> Result<(), Error>
pub fn write_string(
&self,
offset: u32,
value: &str,
max_len: u32
) -> Result<(), Error>
write string to the storage file at the given offset. if the length string is greater than max_length it wil be truncated to the max length.
sourcepub fn read_struct<T: Sized>(&self, offset: u32) -> Result<T, Error>
pub fn read_struct<T: Sized>(&self, offset: u32) -> Result<T, Error>
reads struct T from the storage file at the given offset
sourcepub fn write_struct<T: Sized>(&self, offset: u32, st: &T) -> Result<(), Error>
pub fn write_struct<T: Sized>(&self, offset: u32, st: &T) -> Result<(), Error>
writes struct T to the storage file at the given offset
Auto Trait Implementations
impl !RefUnwindSafe for Storage
impl !Send for Storage
impl !Sync for Storage
impl Unpin for Storage
impl !UnwindSafe for Storage
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more