Skip to content

Commit e768890

Browse files
authored
feat: add named sys traits (#10)
1 parent 0787c1c commit e768890

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ tempfile = "3.4.0"
2525
members = ["."]
2626

2727
[workspace.dependencies]
28-
sys_traits = "0.1.7"
28+
sys_traits = "0.1.10"

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "1.81.0"
2+
channel = "1.86.0"
33
components = ["rustfmt", "clippy"]

src/fs.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,13 @@ pub fn canonicalize_path_maybe_not_exists(
5555
}
5656
}
5757

58-
pub fn atomic_write_file_with_retries<
59-
TSys: FsCreateDirAll
60-
+ FsMetadata
61-
+ FsOpen
62-
+ FsRemoveFile
63-
+ FsRename
64-
+ ThreadSleep
65-
+ SystemRandom,
66-
>(
58+
#[sys_traits::auto_impl]
59+
pub trait AtomicWriteFileWithRetriesSys:
60+
AtomicWriteFileSys + ThreadSleep
61+
{
62+
}
63+
64+
pub fn atomic_write_file_with_retries<TSys: AtomicWriteFileWithRetriesSys>(
6765
sys: &TSys,
6866
file_path: &Path,
6967
data: &[u8],
@@ -86,21 +84,25 @@ pub fn atomic_write_file_with_retries<
8684
}
8785
}
8886

87+
#[sys_traits::auto_impl]
88+
pub trait AtomicWriteFileSys:
89+
FsCreateDirAll + FsMetadata + FsOpen + FsRemoveFile + FsRename + SystemRandom
90+
{
91+
}
92+
8993
/// Writes the file to the file system at a temporary path, then
9094
/// renames it to the destination in a single sys call in order
9195
/// to never leave the file system in a corrupted state.
9296
///
9397
/// This also handles creating the directory if a NotFound error
9498
/// occurs.
95-
pub fn atomic_write_file<
96-
TSys: FsCreateDirAll + FsMetadata + FsOpen + FsRemoveFile + FsRename + SystemRandom,
97-
>(
99+
pub fn atomic_write_file<TSys: AtomicWriteFileSys>(
98100
sys: &TSys,
99101
file_path: &Path,
100102
data: &[u8],
101103
mode: u32,
102104
) -> std::io::Result<()> {
103-
fn atomic_write_file_raw<TSys: FsOpen + FsRename + FsRemoveFile>(
105+
fn atomic_write_file_raw<TSys: AtomicWriteFileSys>(
104106
sys: &TSys,
105107
temp_file_path: &Path,
106108
file_path: &Path,

0 commit comments

Comments
 (0)