FileOpener

Trait FileOpener 

Source
pub trait FileOpener: Send + 'static {
    // Required method
    fn open(&mut self) -> Result<(&dyn FileReader, u64), Error>;

    // Provided method
    fn from_cache(&mut self) -> Option<Result<&[u8], Error>> { ... }
}
Expand description

This trait represents anything that can open the file

You can convert anything that is AsRef<Path> to this trait and it will just open a file at specified path. But often you want some checks of permissions or visibility of the file while opening it. You can’t do even stat() or open() in main loop because even such a simple operation can potentially block for indefinite period of time.

So file opener could be anything that validates a path, caches file descriptor, and in the result returns a file.

Required Methods§

Source

fn open(&mut self) -> Result<(&dyn FileReader, u64), Error>

Open the file

This function is called in disk thread

Provided Methods§

Source

fn from_cache(&mut self) -> Option<Result<&[u8], Error>>

Read file from cache

Note: this can be both positive and negative cache

You don’t have to implement this method if you don’t have in-memory cache of files

Implementors§

Source§

impl FileOpener for PathOpener

Available on Unix only.