diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a76fe69..0213a7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -61,10 +61,10 @@ jobs: uses: taiki-e/install-action@cargo-hack - name: Build crate - run: cargo hack --feature-powerset build --all-targets --verbose + run: cargo hack --workspace --feature-powerset build --all-targets --verbose - name: Test crate - run: cargo hack --feature-powerset test --verbose + run: cargo hack --workspace --feature-powerset test --verbose minimal-versions: runs-on: ubuntu-latest @@ -91,10 +91,10 @@ jobs: tool: cargo-hack,cargo-minimal-versions - name: Build crate - run: cargo minimal-versions --direct --feature-powerset build --all-targets --verbose + run: cargo minimal-versions --direct --workspace --feature-powerset build --all-targets --verbose - name: Test crate - run: cargo minimal-versions --direct --feature-powerset test --verbose + run: cargo minimal-versions --direct --workspace --feature-powerset test --verbose coverage: # This is separate from the main tests because cargo-llvm-cov doesn't run @@ -120,7 +120,7 @@ jobs: tool: cargo-llvm-cov - name: Test with coverage - run: cargo llvm-cov --all-features --lcov --output-path lcov.info + run: cargo llvm-cov --workspace --all-features --lcov --output-path lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 @@ -149,13 +149,13 @@ jobs: uses: taiki-e/install-action@cargo-hack - name: Check code (no tests) - run: cargo hack --feature-powerset clippy -- -Dwarnings + run: cargo hack --workspace --feature-powerset clippy -- -Dwarnings - name: Check code (including tests) - run: cargo hack --feature-powerset clippy --all-targets -- -Dwarnings + run: cargo hack --workspace --feature-powerset clippy --all-targets -- -Dwarnings - name: Check formatting - run: cargo fmt --check + run: cargo fmt --all --check docs: runs-on: ubuntu-latest @@ -173,7 +173,7 @@ jobs: uses: Swatinem/rust-cache@v2 - name: Check docs - run: cargo doc --no-deps --all-features + run: cargo doc --workspace --no-deps --all-features env: RUSTDOCFLAGS: -Dwarnings diff --git a/Cargo.toml b/Cargo.toml index 8453e64..c4018be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,39 +1,31 @@ -[package] -name = "rswodlib" -version = "0.1.0" +[workspace] +members = ["crates/*"] +resolver = "2" + +[workspace.package] edition = "2021" -description = "Assorted Rust utility functions" authors = ["John Thorvald Wodder II "] repository = "https://github.com/jwodder/rswodlib" license = "MIT" -exclude = ["/.*"] -publish = false + +[package] +name = "rswodlib" +edition.workspace = true +description = "Assorted Rust utility functions" +authors.workspace = true +repository.workspace = true +license.workspace = true [dependencies] automod = "1.0.8" -bstr = { version = "1.4.0", default-features = false, features = ["std"] } -futures-util = { version = "0.3.29", default-features = false, features = ["std"], optional = true } -log = "0.4.20" -num-traits = "0.2.15" -pin-project-lite = { version = "0.2.11", optional = true } -shell-words = "1.1.0" -thiserror = "2.0.0" -tokio = { version = "1.29.0", features = ["sync", "time"], optional = true } -tokio-util = { version = "0.7.10", features = ["rt"], optional = true } [dev-dependencies] -assert_fs = "1.0.13" -predicates = "3.0.3" rstest = { version = "0.23.0", default-features = false } -tokio = { version = "1.29.0", features = ["io-util", "macros", "rt"] } - -[build-dependencies] -rustc_version = "0.4.1" -[features] -tokio = ["dep:futures-util", "dep:pin-project-lite", "dep:tokio", "dep:tokio-util"] +[lints] +workspace = true -[lints.rust] +[workspace.lints.rust] # Lint groups: future_incompatible = { level = "deny", priority = -1 } refining_impl_trait = { level = "deny", priority = -1 } @@ -112,7 +104,7 @@ unused_comparisons = "deny" useless_ptr_null_checks = "deny" while_true = "deny" -[lints.rustdoc] +[workspace.lints.rustdoc] bare_urls = "deny" broken_intra_doc_links = "deny" invalid_codeblock_attributes = "deny" @@ -122,7 +114,7 @@ private_intra_doc_links = "deny" redundant_explicit_links = "deny" unescaped_backticks = "deny" -[lints.clippy] +[workspace.lints.clippy] # Deny all warn-by-default lints: all = { level = "deny", priority = -1 } diff --git a/README.md b/README.md index d26a3e6..6da4c5b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,16 @@ [![codecov.io](https://codecov.io/gh/jwodder/rswodlib/branch/master/graph/badge.svg)](https://codecov.io/gh/jwodder/rswodlib) [![MIT License](https://img.shields.io/github/license/jwodder/rswodlib.svg)](https://opensource.org/licenses/MIT) -`rswodlib` is a personal Rust library containing various useful (and often -reused) functions & functionalities that aren't quite worthy of packages of -their own. It is not meant to be installed; instead, if you see anything you -like in it, you are encouraged to copy & paste, subject to the MIT license. +`rswodlib` is a personal collection of [Rust](https://www.rust-lang.org) +functions & functionalities that, though useful and often reused, aren't quite +worthy of published packages of their own. It is not meant to be installed; +instead, if you see anything you like in it, you are encouraged to copy & +paste, subject to the MIT license. + +The project is laid out as a [workspace][] in which the root package contains +only code with no (non-test) dependencies beyond `std` (and [`automod`][], for +convenience) while the other packages (all located in `crates/`) require one or +more third-party dependencies each. + +[workspace]: https://doc.rust-lang.org/cargo/reference/workspaces.html +[`automod`]: https://crates.io/crates/automod diff --git a/crates/generic-num/Cargo.toml b/crates/generic-num/Cargo.toml new file mode 100644 index 0000000..b1821db --- /dev/null +++ b/crates/generic-num/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "rswodlib-generic-num" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +num-traits = "0.2.15" + +[dev-dependencies] +rstest = { version = "0.23.0", default-features = false } + +[lints] +workspace = true diff --git a/src/math/gcd.rs b/crates/generic-num/src/gcd.rs similarity index 100% rename from src/math/gcd.rs rename to crates/generic-num/src/gcd.rs diff --git a/crates/generic-num/src/lib.rs b/crates/generic-num/src/lib.rs new file mode 100644 index 0000000..c4de57e --- /dev/null +++ b/crates/generic-num/src/lib.rs @@ -0,0 +1,4 @@ +mod gcd; +mod modinverse; +pub use crate::gcd::*; +pub use crate::modinverse::*; diff --git a/src/math/modinverse.rs b/crates/generic-num/src/modinverse.rs similarity index 100% rename from src/math/modinverse.rs rename to crates/generic-num/src/modinverse.rs diff --git a/crates/loggedcmd/Cargo.toml b/crates/loggedcmd/Cargo.toml new file mode 100644 index 0000000..0c85b2e --- /dev/null +++ b/crates/loggedcmd/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rswodlib-loggedcmd" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +log = "0.4.20" +shell-words = "1.1.0" +thiserror = "2.0.0" + +[lints] +workspace = true diff --git a/src/cmd/loggedcmd.rs b/crates/loggedcmd/src/lib.rs similarity index 100% rename from src/cmd/loggedcmd.rs rename to crates/loggedcmd/src/lib.rs diff --git a/crates/partition/Cargo.toml b/crates/partition/Cargo.toml new file mode 100644 index 0000000..91b4121 --- /dev/null +++ b/crates/partition/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rswodlib-partition" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] + +[build-dependencies] +rustc_version = "0.4.1" + +[lints] +workspace = true diff --git a/crates/partition/LICENSE b/crates/partition/LICENSE new file mode 120000 index 0000000..30cff74 --- /dev/null +++ b/crates/partition/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/build.rs b/crates/partition/build.rs similarity index 100% rename from build.rs rename to crates/partition/build.rs diff --git a/src/strings/partition.rs b/crates/partition/src/lib.rs similarity index 95% rename from src/strings/partition.rs rename to crates/partition/src/lib.rs index 43eb147..5bbdd91 100644 --- a/src/strings/partition.rs +++ b/crates/partition/src/lib.rs @@ -1,4 +1,5 @@ #![cfg(nightly)] +#![feature(pattern)] // Requires the "pattern" feature on nightly // - `#![feature(pattern)]` must be enabled in the root module // - rswodlib is configured to only make use of nightly features when actually @@ -13,7 +14,7 @@ use std::str::pattern::Pattern; /// # Example /// /// ``` -/// # use rswodlib::strings::partition::partition; +/// # use rswodlib_partition::partition; /// assert_eq!(partition("abc.123-xyz", ['-', '.']), Some(("abc", ".", "123-xyz"))); /// assert_eq!(partition("abc_123_xyz", ['-', '.']), None); /// ``` diff --git a/crates/runcmd/Cargo.toml b/crates/runcmd/Cargo.toml new file mode 100644 index 0000000..74176a0 --- /dev/null +++ b/crates/runcmd/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "rswodlib-runcmd" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +bstr = { version = "1.4.0", default-features = false, features = ["std"] } +rswodlib = { path = "../.." } +thiserror = "2.0.0" + +[dev-dependencies] +assert_fs = "1.0.13" +predicates = "3.0.3" + +[lints] +workspace = true diff --git a/src/cmd/runcmd.rs b/crates/runcmd/src/lib.rs similarity index 97% rename from src/cmd/runcmd.rs rename to crates/runcmd/src/lib.rs index e283b3f..aba03f4 100644 --- a/src/cmd/runcmd.rs +++ b/crates/runcmd/src/lib.rs @@ -1,5 +1,5 @@ -use crate::strings::trim_string::trim_string; use bstr::ByteVec; // into_string_lossy() +use rswodlib::strings::trim_string::trim_string; use std::ffi::OsStr; use std::process::{Command, ExitStatus, Stdio}; use std::str; @@ -112,8 +112,7 @@ mod tests { #[cfg(unix)] mod unix { use super::*; - use assert_fs::prelude::*; - use assert_fs::NamedTempFile; + use assert_fs::{prelude::*, NamedTempFile}; use predicates::prelude::*; #[test] diff --git a/crates/tokio-btn/Cargo.toml b/crates/tokio-btn/Cargo.toml new file mode 100644 index 0000000..4dfac2f --- /dev/null +++ b/crates/tokio-btn/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rswodlib-tokio-btn" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +tokio = { version = "1.29.0", features = ["sync"] } +tokio-util = { version = "0.7.10", features = ["rt"] } + +[lints] +workspace = true diff --git a/src/tokio/btn.rs b/crates/tokio-btn/src/lib.rs similarity index 100% rename from src/tokio/btn.rs rename to crates/tokio-btn/src/lib.rs diff --git a/crates/tokio-buffered-tasks/Cargo.toml b/crates/tokio-buffered-tasks/Cargo.toml new file mode 100644 index 0000000..26fdbb4 --- /dev/null +++ b/crates/tokio-buffered-tasks/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "rswodlib-tokio-buffered-tasks" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +tokio = { version = "1.29.0", features = ["rt", "sync"] } + +[lints] +workspace = true diff --git a/src/tokio/buffered_tasks.rs b/crates/tokio-buffered-tasks/src/lib.rs similarity index 100% rename from src/tokio/buffered_tasks.rs rename to crates/tokio-buffered-tasks/src/lib.rs diff --git a/crates/tokio-lsg/Cargo.toml b/crates/tokio-lsg/Cargo.toml new file mode 100644 index 0000000..61f46be --- /dev/null +++ b/crates/tokio-lsg/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "rswodlib-tokio-lsg" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +tokio = { version = "1.29.0", features = ["sync"] } +tokio-util = { version = "0.7.10", features = ["rt"] } + +[lints] +workspace = true diff --git a/src/tokio/lsg.rs b/crates/tokio-lsg/src/lib.rs similarity index 100% rename from src/tokio/lsg.rs rename to crates/tokio-lsg/src/lib.rs diff --git a/crates/tokio-received-stream/Cargo.toml b/crates/tokio-received-stream/Cargo.toml new file mode 100644 index 0000000..9de8700 --- /dev/null +++ b/crates/tokio-received-stream/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "rswodlib-tokio-received-stream" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +pin-project-lite = "0.2.11" +tokio = { version = "1.29.0", features = ["sync"] } + +[dev-dependencies] +tokio = { version = "1.29.0", features = ["io-util", "macros", "rt"] } + +[lints] +workspace = true diff --git a/src/tokio/received_stream.rs b/crates/tokio-received-stream/src/lib.rs similarity index 100% rename from src/tokio/received_stream.rs rename to crates/tokio-received-stream/src/lib.rs diff --git a/crates/tokio-shutdown-group/Cargo.toml b/crates/tokio-shutdown-group/Cargo.toml new file mode 100644 index 0000000..1655eb3 --- /dev/null +++ b/crates/tokio-shutdown-group/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "rswodlib-tokio-shutdown-group" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +tokio = { version = "1.29.0", features = ["time"] } +tokio-util = { version = "0.7.10", features = ["rt"] } + +[dev-dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +tokio = { version = "1.29.0", features = ["macros", "rt"] } + +[lints] +workspace = true diff --git a/src/tokio/shutdown_group.rs b/crates/tokio-shutdown-group/src/lib.rs similarity index 100% rename from src/tokio/shutdown_group.rs rename to crates/tokio-shutdown-group/src/lib.rs diff --git a/crates/unique-stream/Cargo.toml b/crates/unique-stream/Cargo.toml new file mode 100644 index 0000000..957765b --- /dev/null +++ b/crates/unique-stream/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "rswodlib-unique-stream" +edition.workspace = true +#description = ... +authors.workspace = true +repository.workspace = true +license.workspace = true + +[dependencies] +futures-util = { version = "0.3.29", default-features = false, features = ["std"] } +pin-project-lite = "0.2.11" + +[dev-dependencies] +tokio = { version = "1.29.0", features = ["macros", "rt"] } + +[lints] +workspace = true diff --git a/src/tokio/unique_stream.rs b/crates/unique-stream/src/lib.rs similarity index 100% rename from src/tokio/unique_stream.rs rename to crates/unique-stream/src/lib.rs diff --git a/src/cmd.rs b/src/cmd.rs deleted file mode 100644 index 18084f6..0000000 --- a/src/cmd.rs +++ /dev/null @@ -1 +0,0 @@ -automod::dir!(pub "src/cmd"); diff --git a/src/lib.rs b/src/lib.rs index 05a7d25..44b1149 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1 @@ -#![cfg_attr(nightly, feature(pattern))] - automod::dir!(pub "src"); diff --git a/src/tokio.rs b/src/tokio.rs deleted file mode 100644 index 00d5c9a..0000000 --- a/src/tokio.rs +++ /dev/null @@ -1,3 +0,0 @@ -#![cfg(feature = "tokio")] -//! Functionality for working with tokio -automod::dir!(pub "src/tokio");