Skip to main content

Filesystem

Trait Filesystem 

Source
pub trait Filesystem: Send + Sync {
    // Required method
    fn read_bytes<'life0, 'life1, 'async_trait>(
        &'life0 self,
        asset_path: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FilesystemError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn write_bytes<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        asset_path: &'life1 str,
        data: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), FilesystemError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
}
Expand description

Abstraction for reading files from different storage backends.

This trait allows the asset system to work with different filesystem implementations, such as native filesystem, network storage, or embedded assets. All filesystem operations are async to support non-blocking I/O.

Required Methods§

Source

fn read_bytes<'life0, 'life1, 'async_trait>( &'life0 self, asset_path: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, FilesystemError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Asynchronously reads the contents of an asset file as raw bytes.

This method performs non-blocking I/O to read the entire file into memory. For large files, consider implementing streaming or chunked reading.

§Arguments
  • asset_path - The path to the asset file
§Returns

A future that resolves to the file contents as bytes, or an error if the file could not be read.

Provided Methods§

Source

fn write_bytes<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, asset_path: &'life1 str, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), FilesystemError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Asynchronously writes raw bytes to an asset file.

This method provides a default implementation that returns WriteUnsupported. Filesystem implementations that support writing should override this method.

§Arguments
  • asset_path - The path where the asset file should be written
  • data - The raw bytes to write to the file
§Returns

A future that resolves to success or an error if the write operation fails. The default implementation always returns WriteUnsupported.

Implementors§