git_prole/
fs.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Like [`fs_err`], but the functions are instrumented with [`macro@tracing::instrument`] and return
//! [`miette::Result`] instead of [`std::io::Result`].

use std::fmt::Debug;
use std::path::Path;

use miette::IntoDiagnostic;
use tracing::instrument;

#[instrument(level = "trace")]
pub fn rename<P, Q>(from: P, to: Q) -> miette::Result<()>
where
    P: AsRef<Path> + Debug,
    Q: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::rename(from, to).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn create_dir<P>(path: P) -> miette::Result<()>
where
    P: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::create_dir(path).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn create_dir_all<P>(path: P) -> miette::Result<()>
where
    P: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::create_dir_all(path).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn remove_dir<P>(path: P) -> miette::Result<()>
where
    P: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::remove_dir(path).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn read_to_string<P>(path: P) -> miette::Result<String>
where
    P: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::read_to_string(path).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn copy<P, Q>(from: P, to: Q) -> miette::Result<u64>
where
    P: AsRef<Path> + Debug,
    Q: AsRef<Path> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::copy(from, to).into_diagnostic()
}

#[instrument(level = "trace")]
pub fn write<P, C>(path: P, contents: C) -> miette::Result<()>
where
    P: AsRef<Path> + Debug,
    C: AsRef<[u8]> + Debug,
{
    #[expect(clippy::disallowed_methods)]
    fs_err::write(path, contents).into_diagnostic()
}