|
| 1 | +use camino::{Utf8Path, Utf8PathBuf}; |
1 | 2 | use snafu::prelude::*; |
2 | | -use std::path::{Path, PathBuf}; |
3 | 3 |
|
4 | 4 | #[derive(Snafu, Debug)] |
5 | | -#[snafu(display("failed to create directory {} and parents", path.display()))] |
| 5 | +#[snafu(display("failed to create directory {path} and parents"))] |
6 | 6 | pub struct CreateDirAllError { |
7 | | - pub path: PathBuf, |
| 7 | + pub path: Utf8PathBuf, |
8 | 8 | pub source: std::io::Error, |
9 | 9 | } |
10 | 10 |
|
11 | | -pub fn create_dir_all(path: impl AsRef<Path>) -> Result<(), CreateDirAllError> { |
| 11 | +pub fn create_dir_all(path: impl AsRef<Utf8Path>) -> Result<(), CreateDirAllError> { |
12 | 12 | let path = path.as_ref(); |
13 | 13 | std::fs::create_dir_all(path).context(CreateDirAllSnafu { path }) |
14 | 14 | } |
15 | 15 |
|
16 | 16 | #[derive(Snafu, Debug)] |
17 | | -#[snafu(display("failed to read {}", path.display()))] |
| 17 | +#[snafu(display("failed to read {path}"))] |
18 | 18 | pub struct ReadFileError { |
19 | | - pub path: PathBuf, |
| 19 | + pub path: Utf8PathBuf, |
20 | 20 | pub source: std::io::Error, |
21 | 21 | } |
22 | 22 |
|
23 | | -pub fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>, ReadFileError> { |
| 23 | +pub fn read<P: AsRef<Utf8Path>>(path: P) -> Result<Vec<u8>, ReadFileError> { |
24 | 24 | let path = path.as_ref(); |
25 | 25 | std::fs::read(path).context(ReadFileSnafu { path }) |
26 | 26 | } |
27 | 27 |
|
28 | | -pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String, ReadFileError> { |
| 28 | +pub fn read_to_string<P: AsRef<Utf8Path>>(path: P) -> Result<String, ReadFileError> { |
29 | 29 | let path = path.as_ref(); |
30 | 30 | std::fs::read_to_string(path).context(ReadFileSnafu { path }) |
31 | 31 | } |
32 | 32 |
|
33 | 33 | #[derive(Snafu, Debug)] |
34 | | -#[snafu(display("failed to remove directory {} and contents", path.display()))] |
| 34 | +#[snafu(display("failed to remove directory {path} and contents"))] |
35 | 35 | pub struct RemoveDirAllError { |
36 | | - pub path: PathBuf, |
| 36 | + pub path: Utf8PathBuf, |
37 | 37 | pub source: std::io::Error, |
38 | 38 | } |
39 | 39 |
|
40 | | -pub fn remove_dir_all(path: &Path) -> Result<(), RemoveDirAllError> { |
| 40 | +pub fn remove_dir_all(path: impl AsRef<Utf8Path>) -> Result<(), RemoveDirAllError> { |
| 41 | + let path = path.as_ref(); |
41 | 42 | std::fs::remove_dir_all(path).context(RemoveDirAllSnafu { path }) |
42 | 43 | } |
43 | 44 |
|
44 | 45 | #[derive(Snafu, Debug)] |
45 | | -#[snafu(display("failed to remove file {}", path.display()))] |
| 46 | +#[snafu(display("failed to remove file {path}"))] |
46 | 47 | pub struct RemoveFileError { |
47 | | - pub path: PathBuf, |
| 48 | + pub path: Utf8PathBuf, |
48 | 49 | pub source: std::io::Error, |
49 | 50 | } |
50 | 51 |
|
51 | | -pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<(), RemoveFileError> { |
| 52 | +pub fn remove_file<P: AsRef<Utf8Path>>(path: P) -> Result<(), RemoveFileError> { |
52 | 53 | let path = path.as_ref(); |
53 | 54 | std::fs::remove_file(path).context(RemoveFileSnafu { path }) |
54 | 55 | } |
55 | 56 |
|
56 | 57 | #[derive(Snafu, Debug)] |
57 | | -#[snafu(display("failed to write {}", path.display()))] |
| 58 | +#[snafu(display("failed to write {path}"))] |
58 | 59 | pub struct WriteFileError { |
59 | | - pub path: PathBuf, |
| 60 | + pub path: Utf8PathBuf, |
60 | 61 | pub source: std::io::Error, |
61 | 62 | } |
62 | 63 |
|
63 | | -pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> Result<(), WriteFileError> { |
| 64 | +pub fn write<P: AsRef<Utf8Path>, C: AsRef<[u8]>>( |
| 65 | + path: P, |
| 66 | + contents: C, |
| 67 | +) -> Result<(), WriteFileError> { |
64 | 68 | let path = path.as_ref(); |
65 | 69 | std::fs::write(path, contents).context(WriteFileSnafu { path }) |
66 | 70 | } |
0 commit comments