Storage

Struct Storage 

Source
pub struct Storage<M>{ /* private fields */ }
Expand description

A mounted storage partition.

Implementations§

Source§

impl<M> Storage<M>

Source

pub async fn mount(partition: M) -> Result<Self, StorageError>

Mounts the filesystem.

Returns an error if the filesystem is not formatted.

Source

pub async fn format(partition: &mut M) -> Result<(), StorageError>

Unconditionally formats the filesystem.

Source

pub async fn format_and_mount(partition: M) -> Result<Self, StorageError>

Unconditionally formats then mounts the filesystem.

Source

pub fn capacity(&self) -> usize

Returns the total capacity of the filesystem in bytes.

Source

pub fn free_bytes(&self) -> usize

Returns the number of free bytes in the filesystem.

Note: this function does not count deleted files as free space, so the result will not match the value capacity() - used_bytes().

Source

pub async fn used_bytes(&mut self) -> Result<usize, StorageError>

Returns the number of bytes used in the filesystem.

This function takes filesystem overhead into account, but does not count deleted files.

Source

pub async fn delete(&mut self, path: &str) -> Result<(), StorageError>

Deletes the file at path.

Source

pub async fn store( &mut self, path: &str, data: &[u8], if_exists: OnCollision, ) -> Result<(), StorageError>

Creates a new file at path with the given data.

If a file already exists at path, the behaviour is determined by if_exists.

  • OnCollision::Overwrite will overwrite the existing file.
  • OnCollision::Fail will return an error.
Source

pub async fn exists(&mut self, path: &str) -> bool

Convenience method for checking if a file exists. Ignores all errors.

Source

pub async fn read(&mut self, path: &str) -> Result<Reader<M>, StorageError>

Opens the file at path for reading.

Returns a reader object on success and an error on failure.

Modifying the filesystem while a reader is open results in undefined behaviour.

Source

pub async fn file_size(&mut self, path: &str) -> Result<usize, StorageError>

Returns the content size of the file at path.

Source§

impl<P> Storage<Counters<P>>

Source

pub fn erase_count(&self) -> usize

Source

pub fn read_count(&self) -> usize

Source

pub fn write_count(&self) -> usize

Auto Trait Implementations§

§

impl<M> Freeze for Storage<M>
where M: Freeze,

§

impl<M> RefUnwindSafe for Storage<M>
where M: RefUnwindSafe,

§

impl<M> Send for Storage<M>
where M: Send,

§

impl<M> Sync for Storage<M>
where M: Sync,

§

impl<M> Unpin for Storage<M>
where M: Unpin,

§

impl<M> UnwindSafe for Storage<M>
where M: 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>,

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.