pub trait FilePath {
// Required method
fn path(&self) -> Result<PathBuf>;
}
Expand description
An extension trait for std::fs::File
providing a path
method.
Required Methods§
Sourcefn path(&self) -> Result<PathBuf>
fn path(&self) -> Result<PathBuf>
Returns the path of this file.
The path might be wrong for example after moving a file.
§Platform-specific behavior
This function currently uses /proc/self/fd/
on Linux, fcntl
with F_GETPATH
on macOS
and GetFinalPathNameByHandle
on Windows.
§Examples
use std::fs::File;
use std::io;
use filepath::FilePath;
fn main() -> io::Result<()> {
let file = File::open("some_file")?;
let path = file.path()?;
Ok(())
}