Skip to content

Commit

Permalink
future proof style external crate support (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Nov 30, 2024
1 parent 20620db commit 6bd7086
Show file tree
Hide file tree
Showing 23 changed files with 255 additions and 78 deletions.
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fs4"
# NB: When modifying, also modify html_root_url in lib.rs
version = "0.11.1"
version = "0.12.0"
rust-version = "1.75.0"
authors = ["Dan Burkert <dan@danburkert.com>", "Al Liu <scygliu1@gmail.com>"]
license = "MIT OR Apache-2.0"
Expand All @@ -18,8 +18,11 @@ sync = []
async-std = ["dep:async-std"]
tokio = ["dep:tokio"]
smol = ["dep:smol"]
fs-err = ["dep:fs-err", "fs-err/io_safety"]
fs-err-tokio = ["fs-err", "fs-err/tokio"]
fs-err2 = ["dep:fs-err2", "fs-err2/io_safety"]
fs-err2-tokio = ["fs-err2", "fs-err2/tokio"]
fs-err3 = ["dep:fs-err3"]
fs-err3-tokio = ["fs-err3", "fs-err3/tokio"]


[target.'cfg(not(windows))'.dependencies]
rustix = { version = "0.38", features = ["fs"] }
Expand All @@ -30,15 +33,17 @@ features = ["Win32_Foundation", "Win32_Storage_FileSystem", "Win32_System_IO"]

[dependencies]
async-std = { version = "1", optional = true }
fs-err = { version = "2", optional = true }
fs-err2 = { package = "fs-err", version = "2", optional = true }
fs-err3 = { package = "fs-err", version = "3", optional = true }
smol = { version = "2", optional = true }
tokio = { version = "1", optional = true, default-features = false, features = [
"fs",
] }

[dev-dependencies]
async-std = { version = "1", features = ["attributes"] }
fs-err = { version = "2", features = ["io_safety", "tokio"] }
fs-err2 = { package = "fs-err", version = "2", features = ["io_safety", "tokio"] }
fs-err3 = { package = "fs-err", version = "3", features = ["tokio"] }
smol-potat = "1.1"
tempdir = "0.3"
tokio = { version = "1", features = ["full"] }
Expand Down
28 changes: 20 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,49 @@ This is a fork of the [fs2-rs](https://github.com/danburkert/fs2-rs) crate, the
- std
```toml
[dependencies]
fs4 = { version = "0.11", features = ["sync"] }
fs4 = { version = "0.12", features = ["sync"] }
```

- [async-std runtime](https://crates.io/crates/async-std)
```toml
[dependencies]
fs4 = { version = "0.11", features = ["async-std"] }
fs4 = { version = "0.12", features = ["async-std"] }
```

- [fs-err](https://crates.io/crates/fs-err)
- [fs-err v2](https://crates.io/crates/fs-err)
```toml
[dependencies]
fs4 = { version = "0.11", features = ["fs-err"] }
fs4 = { version = "0.12", features = ["fs-err2"] }
```

- [fs-err-tokio](https://crates.io/crates/fs-err)
- [fs-err-tokio v2](https://crates.io/crates/fs-err)
```toml
[dependencies]
fs4 = { version = "0.11", features = ["fs-err-tokio"] }
fs4 = { version = "0.12", features = ["fs-err2-tokio"] }
```

- [fs-err v3](https://crates.io/crates/fs-err)
```toml
[dependencies]
fs4 = { version = "0.12", features = ["fs-err3"] }
```

- [fs-err-tokio v3](https://crates.io/crates/fs-err)
```toml
[dependencies]
fs4 = { version = "0.12", features = ["fs-err3-tokio"] }
```

- [smol runtime](https://crates.io/crates/smol)
```toml
[dependencies]
fs4 = { version = "0.11", features = ["smol"] }
fs4 = { version = "0.12", features = ["smol"] }
```

- [tokio runtime](https://crates.io/crates/tokio)
```toml
[dependencies]
fs4 = { version = "0.11", features = ["tokio"] }
fs4 = { version = "0.12", features = ["tokio"] }
```

## Features
Expand Down
8 changes: 6 additions & 2 deletions src/file_ext/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,12 @@ cfg_async_std! {
pub(crate) mod async_std_impl;
}

cfg_fs_err_tokio! {
pub(crate) mod fs_err_tokio_impl;
cfg_fs_err2_tokio! {
pub(crate) mod fs_err2_tokio_impl;
}

cfg_fs_err3_tokio! {
pub(crate) mod fs_err3_tokio_impl;
}

cfg_smol! {
Expand Down
13 changes: 13 additions & 0 deletions src/file_ext/async_impl/fs_err2_tokio_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(unix)]
use crate::unix::async_impl::fs_err2_tokio_impl as sys;
#[cfg(windows)]
use crate::windows::async_impl::fs_err2_tokio_impl as sys;
use fs_err2::tokio::File;

async_file_ext!(File, "fs_err::tokio::File");

test_mod! {
tokio::test,
use crate::fs_err2_tokio::AsyncFileExt;
use fs_err2::tokio as fs;
}
13 changes: 13 additions & 0 deletions src/file_ext/async_impl/fs_err3_tokio_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#[cfg(unix)]
use crate::unix::async_impl::fs_err3_tokio_impl as sys;
#[cfg(windows)]
use crate::windows::async_impl::fs_err3_tokio_impl as sys;
use fs_err3::tokio::File;

async_file_ext!(File, "fs_err::tokio::File");

test_mod! {
tokio::test,
use crate::fs_err3_tokio::AsyncFileExt;
use fs_err3::tokio as fs;
}
13 changes: 0 additions & 13 deletions src/file_ext/async_impl/fs_err_tokio_impl.rs

This file was deleted.

8 changes: 6 additions & 2 deletions src/file_ext/sync_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ cfg_sync! {
pub(crate) mod std_impl;
}

cfg_fs_err! {
pub(crate) mod fs_err_impl;
cfg_fs2_err! {
pub(crate) mod fs_err2_impl;
}

cfg_fs3_err! {
pub(crate) mod fs_err3_impl;
}
11 changes: 11 additions & 0 deletions src/file_ext/sync_impl/fs_err2_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(unix)]
use crate::unix::sync_impl::fs_err2_impl as sys;
#[cfg(windows)]
use crate::windows::sync_impl::fs_err2_impl as sys;
use fs_err2::File;

file_ext!(File, "fs_err::File");

test_mod! {
use fs_err2 as fs;
}
11 changes: 11 additions & 0 deletions src/file_ext/sync_impl/fs_err3_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#[cfg(unix)]
use crate::unix::sync_impl::fs_err3_impl as sys;
#[cfg(windows)]
use crate::windows::sync_impl::fs_err3_impl as sys;
use fs_err3::File;

file_ext!(File, "fs_err::File");

test_mod! {
use fs_err3 as fs;
}
11 changes: 0 additions & 11 deletions src/file_ext/sync_impl/fs_err_impl.rs

This file was deleted.

78 changes: 61 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Extended utilities for working with files and filesystems in Rust.
#![doc(html_root_url = "https://docs.rs/fs4/0.11.0")]
#![doc(html_root_url = "https://docs.rs/fs4/0.12.0")]
#![cfg_attr(test, feature(test))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, allow(unused_attributes))]
#![allow(unexpected_cfgs)]
#![allow(unexpected_cfgs, unstable_name_collisions)]

#[cfg(windows)]
extern crate windows_sys;
Expand All @@ -20,21 +20,43 @@ macro_rules! cfg_async_std {

// This lint is a bug, it is being used in multiple places.
#[allow(unused_macros)]
macro_rules! cfg_fs_err {
macro_rules! cfg_fs_err2 {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err")))]
#[cfg(feature = "fs-err2")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err2")))]
$item
)*
}
}

macro_rules! cfg_fs_err_tokio {
macro_rules! cfg_fs_err2_tokio {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err-tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err-tokio")))]
#[cfg(feature = "fs-err2-tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err2-tokio")))]
$item
)*
}
}

// This lint is a bug, it is being used in multiple places.
#[allow(unused_macros)]
macro_rules! cfg_fs_err3 {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err3")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err3")))]
$item
)*
}
}

macro_rules! cfg_fs_err3_tokio {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err3-tokio")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err3-tokio")))]
$item
)*
}
Expand Down Expand Up @@ -70,11 +92,21 @@ macro_rules! cfg_sync {
}
}

macro_rules! cfg_fs_err {
macro_rules! cfg_fs2_err {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err2")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err2")))]
$item
)*
}
}

macro_rules! cfg_fs3_err {
($($item:item)*) => {
$(
#[cfg(feature = "fs-err")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err")))]
#[cfg(feature = "fs-err3")]
#[cfg_attr(docsrs, doc(cfg(feature = "fs-err3")))]
$item
)*
}
Expand Down Expand Up @@ -109,9 +141,15 @@ cfg_sync!(
}
);

cfg_fs_err!(
pub mod fs_err {
pub use crate::file_ext::sync_impl::fs_err_impl::FileExt;
cfg_fs_err2!(
pub mod fs_err2 {
pub use crate::file_ext::sync_impl::fs_err2_impl::FileExt;
}
);

cfg_fs_err3!(
pub mod fs_err3 {
pub use crate::file_ext::sync_impl::fs_err3_impl::FileExt;
}
);

Expand All @@ -121,9 +159,15 @@ cfg_async_std!(
}
);

cfg_fs_err_tokio!(
pub mod fs_err_tokio {
pub use crate::file_ext::async_impl::fs_err_tokio_impl::AsyncFileExt;
cfg_fs_err2_tokio!(
pub mod fs_err2_tokio {
pub use crate::file_ext::async_impl::fs_err2_tokio_impl::AsyncFileExt;
}
);

cfg_fs_err3_tokio!(
pub mod fs_err3_tokio {
pub use crate::file_ext::async_impl::fs_err3_tokio_impl::AsyncFileExt;
}
);

Expand Down
8 changes: 6 additions & 2 deletions src/unix/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,12 @@ cfg_async_std! {
pub(crate) mod async_std_impl;
}

cfg_fs_err_tokio! {
pub(crate) mod fs_err_tokio_impl;
cfg_fs_err2_tokio! {
pub(crate) mod fs_err2_tokio_impl;
}

cfg_fs_err3_tokio! {
pub(crate) mod fs_err3_tokio_impl;
}

cfg_smol! {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fs_err::tokio::File;
use fs_err2::tokio::File;
use std::os::unix::fs::MetadataExt;
use std::os::unix::io::AsRawFd;

Expand All @@ -8,6 +8,6 @@ allocate_size!(File);

test_mod! {
tokio::test,
use crate::fs_err_tokio::AsyncFileExt;
use fs_err::tokio as fs;
use crate::fs_err2_tokio::AsyncFileExt;
use fs_err2::tokio as fs;
}
13 changes: 13 additions & 0 deletions src/unix/async_impl/fs_err3_tokio_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use fs_err3::tokio::File;
use std::os::unix::fs::MetadataExt;
use std::os::unix::io::AsRawFd;

lock_impl!(File);
allocate!(File);
allocate_size!(File);

test_mod! {
tokio::test,
use crate::fs_err3_tokio::AsyncFileExt;
use fs_err3::tokio as fs;
}
8 changes: 6 additions & 2 deletions src/unix/sync_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ cfg_sync! {
pub(crate) mod std_impl;
}

cfg_fs_err! {
pub(crate) mod fs_err_impl;
cfg_fs_err2! {
pub(crate) mod fs_err2_impl;
}

cfg_fs_err3! {
pub(crate) mod fs_err3_impl;
}
Loading

0 comments on commit 6bd7086

Please sign in to comment.