Dir

Trait Dir 

Source
pub trait Dir {
    type Read: Read;
    type Write: Write;

    // Required methods
    fn open_file(&mut self, name: &str) -> Result<Self::Read, FSError>;
    fn create_file(&mut self, name: &str) -> Result<Self::Write, FSError>;
    fn append_file(&mut self, name: &str) -> Result<Self::Write, FSError>;
    fn get_file_size(&mut self, name: &str) -> Result<u32, FSError>;
    fn remove_file(&mut self, name: &str) -> Result<(), FSError>;
    fn iter_dir<F>(&mut self, f: F) -> Result<(), FSError>
       where F: FnMut(EntryKind, &[u8]);
}

Required Associated Types§

Required Methods§

Source

fn open_file(&mut self, name: &str) -> Result<Self::Read, FSError>

Open a file for reading.

The file path is given as a slice of path components. There are at least 4 components:

  1. the first one is the root directory (either “roms” or “data”),
  2. the second is the author ID,
  3. the third is the app ID,
  4. (optional) directory names if the file is nested,
  5. and the last is file name.

The runtime ensures that the path is relative and never goes up the tree.

The whole filesystem abstraction (this method and the ones below) is designed to work nicely with embedded_sdmmc and the stdlib filesystem.

Source

fn create_file(&mut self, name: &str) -> Result<Self::Write, FSError>

Create a new file and open it for write.

If the file already exists, it will be overwritten.

Source

fn append_file(&mut self, name: &str) -> Result<Self::Write, FSError>

Write data to the end of the file.

Source

fn get_file_size(&mut self, name: &str) -> Result<u32, FSError>

Get file size in bytes.

None should be returned if file not found.

Source

fn remove_file(&mut self, name: &str) -> Result<(), FSError>

Delete the given file if exists.

Directories cannot be removed.

Returns false only if there is an error.

Source

fn iter_dir<F>(&mut self, f: F) -> Result<(), FSError>
where F: FnMut(EntryKind, &[u8]),

Call the callback for each entry in the given directory.

A better API would be to return an iterator but embedded-sdmmc-rs doesn’t support it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Dir for DirImpl

Source§

type Read = File

Source§

type Write = File