Trait tk_sendfile::FileOpener
[−]
[src]
pub trait FileOpener: Send + 'static { fn open(&mut self) -> Result<(&FileReader, u64), Error>; fn from_cache(&mut self) -> Option<Result<&[u8], Error>> { ... } }
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
fn open(&mut self) -> Result<(&FileReader, u64), Error>
Open the file
This function is called in disk thread
Provided Methods
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
impl FileOpener for PathOpener