1 | use std::fs;
|
2 | use std::io;
|
3 | use std::path::{Path, PathBuf};
|
4 |
|
5 | /// Defines aliases on [`Path`](https://doc.rust-lang.org/std/path/struct.Path.html) for `fs_err` functions.
|
6 | ///
|
7 | /// This trait is sealed and can not be implemented by other crates.
|
8 | //
|
9 | // Because no one else can implement it, we can add methods backwards-compatibly.
|
10 | pub trait PathExt: crate::Sealed {
|
11 | /// Wrapper for [`crate::metadata`].
|
12 | fn fs_err_metadata(&self) -> io::Result<fs::Metadata>;
|
13 | /// Wrapper for [`crate::symlink_metadata`].
|
14 | fn fs_err_symlink_metadata(&self) -> io::Result<fs::Metadata>;
|
15 | /// Wrapper for [`crate::canonicalize`].
|
16 | fn fs_err_canonicalize(&self) -> io::Result<PathBuf>;
|
17 | /// Wrapper for [`crate::read_link`].
|
18 | fn fs_err_read_link(&self) -> io::Result<PathBuf>;
|
19 | /// Wrapper for [`crate::read_dir`].
|
20 | fn fs_err_read_dir(&self) -> io::Result<crate::ReadDir>;
|
21 | }
|
22 |
|
23 | impl PathExt for Path {
|
24 | fn fs_err_metadata(&self) -> io::Result<fs::Metadata> {
|
25 | crate::metadata(self)
|
26 | }
|
27 |
|
28 | fn fs_err_symlink_metadata(&self) -> io::Result<fs::Metadata> {
|
29 | crate::symlink_metadata(self)
|
30 | }
|
31 |
|
32 | fn fs_err_canonicalize(&self) -> io::Result<PathBuf> {
|
33 | crate::canonicalize(self)
|
34 | }
|
35 |
|
36 | fn fs_err_read_link(&self) -> io::Result<PathBuf> {
|
37 | crate::read_link(self)
|
38 | }
|
39 |
|
40 | fn fs_err_read_dir(&self) -> io::Result<crate::ReadDir> {
|
41 | crate::read_dir(self)
|
42 | }
|
43 | }
|
44 | |