From 32fe579f67e5b766269b18e281c2666bd05bea6c Mon Sep 17 00:00:00 2001 From: KodrAus Date: Tue, 2 Nov 2021 07:49:27 +1000 Subject: [PATCH 1/4] add support for arbitrary --- .github/workflows/ci.yml | 2 +- Cargo.toml | 8 +++++++- src/lib.rs | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 707c9f39..e31bf596 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,7 +62,7 @@ jobs: run: cargo test --all-features --examples - name: Powerset - run: cargo hack test --feature-powerset --lib --optional-deps serde --depth 3 + run: cargo hack test --feature-powerset --lib --optional-deps "serde arbitrary" --depth 3 msrv: name: "Tests / MSRV / OS: ${{ matrix.os }}" diff --git a/Cargo.toml b/Cargo.toml index 0d904775..7f95eb9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,7 +97,7 @@ default-features = false optional = true version = "0.9" -# Public: Re-expored +# Public: Re-exported [dependencies.uuid_macro] path = "macros" optional = true @@ -113,6 +113,12 @@ version = "1.0.56" optional = true version = "2" +# Public: Used in trait impls on `Uuid` +[dependencies.arbitrary] +optional = true +version = "1" +features = ["derive"] + # Public (unstable): Used in `zerocopy` derive [dependencies.zerocopy] optional = true diff --git a/src/lib.rs b/src/lib.rs index 16f00671..102be5ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -43,6 +43,7 @@ //! * `macros` - adds the `uuid!` macro that can parse UUIDs at compile time. //! * `serde` - adds the ability to serialize and deserialize a UUID using the //! `serde` crate. +//! * `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid`. //! * `fast-rng` - when combined with `v4` uses a faster algorithm for //! generating random UUIDs. This feature requires more dependencies to //! compile, but is just as suitable for UUIDs as the default algorithm. @@ -189,6 +190,9 @@ compile_error!("The `zerocopy-unstable` feature is unstable and may break betwee #[cfg(feature = "zerocopy-unstable")] use zerocopy::{AsBytes, FromBytes, Unaligned}; +#[cfg(feature = "arbitrary")] +use arbitrary::Arbitrary; + mod builder; mod error; mod parser; @@ -355,6 +359,7 @@ pub enum Variant { feature = "zerocopy-unstable", derive(AsBytes, FromBytes, Unaligned) )] +#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] #[repr(transparent)] pub struct Uuid(Bytes); From 93ead9b498e6bd550b020bc99892f558d912f8a6 Mon Sep 17 00:00:00 2001 From: KodrAus Date: Tue, 2 Nov 2021 07:49:45 +1000 Subject: [PATCH 2/4] tweak templates a bit --- .cargo/.gitignore | 1 - .github/ISSUE_TEMPLATE/Bug_report.md | 21 ++++-------- .github/ISSUE_TEMPLATE/Feature_request.md | 19 +++++------ .github/ISSUE_TEMPLATE/tracker | 16 --------- .github/PULL_REQUEST_TEMPLATE.md | 11 ------- .github/PULL_REQUEST_TEMPLATE/release | 16 --------- CODEOWNERS | 16 --------- CONTRIBUTING.md | 40 +++++++++-------------- README.md | 1 + 9 files changed, 31 insertions(+), 110 deletions(-) delete mode 100644 .cargo/.gitignore delete mode 100644 .github/ISSUE_TEMPLATE/tracker delete mode 100644 .github/PULL_REQUEST_TEMPLATE/release delete mode 100644 CODEOWNERS diff --git a/.cargo/.gitignore b/.cargo/.gitignore deleted file mode 100644 index 50cf6ded..00000000 --- a/.cargo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/config diff --git a/.github/ISSUE_TEMPLATE/Bug_report.md b/.github/ISSUE_TEMPLATE/Bug_report.md index 86351cdb..33d9118d 100644 --- a/.github/ISSUE_TEMPLATE/Bug_report.md +++ b/.github/ISSUE_TEMPLATE/Bug_report.md @@ -4,28 +4,21 @@ about: Create a report to help us improve --- -**Describe the bug** +**What happened?** A clear and concise description of what the bug is. -**To Reproduce** Steps to reproduce the behavior: 1. ... 2. ... 3. ... -**Expected behavior** +**What were you expecting?** A clear and concise description of what you expected to happen. -**Screenshots** -If applicable, add screenshots to help explain your problem. +**What's the context?** +- Target (`rustc --version`) +- Version (e.g. `1.0`) +- Cargo features enabled -**Specifications (please complete the following information):** -- Target -- Version [e.g. 1.0] -- Features Enabled - -**Additional context** -Add any other context about the problem here. - -**Other** +**Anything else?** Other information like relevant issues, external links, etc \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/Feature_request.md b/.github/ISSUE_TEMPLATE/Feature_request.md index c1cc0c27..7f2a65c6 100644 --- a/.github/ISSUE_TEMPLATE/Feature_request.md +++ b/.github/ISSUE_TEMPLATE/Feature_request.md @@ -1,23 +1,20 @@ --- name: Feature request -about: Suggest an idea for this project +about: Suggest an idea for UUID --- -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] +**Motivation** +A clear and concise description of what the problem is. -**Describe the solution you'd like** +**Solution** A clear and concise description of what you want to happen. -**Is it blocking?** -Is this issue blocking any of your work? If it is blocking any open source project, you can share the link of the issue - -**Describe alternatives you've considered** +**Alternatives** A clear and concise description of any alternative solutions or features you've considered. -**Additional context** -Add any other context or screenshots about the feature request here. +**Is it blocking?** +Is this issue blocking any of your work? If it is blocking any open source project, you can share the link of the issue -**Other** +**Anything else?** Other information like relevant issues, external links, etc diff --git a/.github/ISSUE_TEMPLATE/tracker b/.github/ISSUE_TEMPLATE/tracker deleted file mode 100644 index bc764320..00000000 --- a/.github/ISSUE_TEMPLATE/tracker +++ /dev/null @@ -1,16 +0,0 @@ - - - -Items left to do for __*version*__ release: - -* [ ] Update version numbers -* [ ] Push to crates.io -* [ ] Write release notes on: - * [ ] Github Releases - * [ ] users.rust-lang.org diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index ff0eb5ac..5384cfd8 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,16 +1,5 @@ - - **I'm submitting a(n)** (bug fix|deprecation|feature|refactor|removal|other) - # Description -# Motivation - -# Tests - - # Related Issue(s) diff --git a/.github/PULL_REQUEST_TEMPLATE/release b/.github/PULL_REQUEST_TEMPLATE/release deleted file mode 100644 index e84bc5c1..00000000 --- a/.github/PULL_REQUEST_TEMPLATE/release +++ /dev/null @@ -1,16 +0,0 @@ - - - -Items left to do for __*version*__ release: - -* [ ] Update version numbers - * [ ] lib.rs - * [ ] Cargo.toml - -Reference: # diff --git a/CODEOWNERS b/CODEOWNERS deleted file mode 100644 index f20b6886..00000000 --- a/CODEOWNERS +++ /dev/null @@ -1,16 +0,0 @@ -# CI -.travis.yml @kinggoesgaming @KodrAus @Dylan-DPC @radix -appveyor.yml @kinggoesgaming @KodrAus @Dylan-DPC @radix - -# Cargo.toml -Cargo.toml @kinggoesgaming @KodrAus @Dylan-DPC @radix - -# Rust -*.rs @kinggoesgaming @KodrAus @Dylan-DPC @radix - -# CODEOWNERS -CODEOWNERS @kinggoesgaming @KodrAus @Dylan-DPC @radix - -#>> Critical -# bors.toml file -bors.toml @kinggoesgaming @KodrAus @Dylan-DPC @radix diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 89fabc53..754fa27e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,7 @@ Thank you for your interest in contributing to the Uuid Project! * [Helpful Links](#helpful-links) For any questions, please make a post on [users.rust-lang.org][u-r-l-o], post -on [uuid-rs mailing list] or join our [gitter] channel. +on [uuid-rs mailing list]. > All contributors need to follow our [Code of Conduct]. @@ -22,10 +22,9 @@ on [uuid-rs mailing list] or join our [gitter] channel. # Feature Requests [Feature Requests]: #feature-requests -The `uuid` crate is still in flux. All features desired may not be present. As -such you are welcome to request for new features. Keep in mind that `uuid` is -a general purpose library. We want to provide features that most users would -find useful. As such not every feature may be accepted. +The `uuid` crate is stable so features that require breaking changes can't be +accepted. There are bound to be usability gaps that can be filled with non-breaking +features though! If you have the chance, please [search existing issues], as there is a chance that someone has already requested your feature. @@ -36,8 +35,17 @@ your request. You can request your feature by following [this link][Feature Request Link] and filling it in. -> We welcome pull requests for your own feature requests, provided they have -been discussed. +> We welcome pull requests for your own feature requests. Discussion should stay +on the relevant issue to make it easier to find. + +## Adding new unstable dependencies + +If a feature introduces a new unstable dependency then it needs to be private. +That means traits and types from the unstable library can't be visible in `uuid`'s +own public API. + +To implement unstable traits, see the precedent set by the `zerocopy-unstable` feature. +It implements a public unstable trait on `Uuid`, but uses the `uuid_unstable` cfg flag. [Feature Request Link]: https://github.com/uuid-rs/uuid/issues/new?template=Feature_request.md @@ -82,12 +90,6 @@ patches), we require PRs to relevant issues. Please open PRs against the `main` branch. -If the pull request is still a work in progress, prepend`[WIP] ` in your -title. `WIP bot` will make sure that the PR doesn't accidentally get merged. - -> Uuid Project has a minimum rust version policy. Currently `uuid` should -compile with at least `1.22.0`, and is enforced on our CI builds. - When you feel that the PR is ready, please ping one of the maintainers so they can review your changes. @@ -117,18 +119,6 @@ You can follow [this link][lrus] to look for issues like this. [lrus]: https://github.com/uuid-rs/uuid/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc -# Out-of-tree Contributions -[Out-of-tree Contributions]: #out-of-tree-contributions - -You can contribute to Uuid in other ways: - -* Answer questions on [users.rust-lang.org][u-r-l-o], [uuid-rs mailing list] and/or -[gitter] channel. -* Find the [crates depending on `uuid`][dependent] and sending PRs to them, -helping them keep their version of `uuid` up-to-date. - -[dependent]: https://crates.io/crates/uuid/reverse_dependencies - # Helpful Links [Helpful Links]: #helpful-links diff --git a/README.md b/README.md index b087e1bf..3d0f52a3 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ various pieces of functionality: * `macros` - adds the `uuid!` macro that can parse UUIDs at compile time. * `serde` - adds the ability to serialize and deserialize a `Uuid` using the `serde` crate. +* `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid`. * `fast-rng` - when combined with `v4` uses a faster algorithm for generating random UUIDs. This feature requires more dependencies to compile, but is just as suitable for UUIDs as the default algorithm. From 477e26e318121e92b14e959a3d4a1031cbc4d10f Mon Sep 17 00:00:00 2001 From: KodrAus Date: Tue, 2 Nov 2021 08:00:45 +1000 Subject: [PATCH 3/4] move external impls to new module --- Cargo.toml | 1 - examples/windows_guid.rs | 5 +--- src/external/arbitrary_support.rs | 43 +++++++++++++++++++++++++++++ src/external/mod.rs | 6 ++++ src/{ => external}/serde_support.rs | 0 src/{ => external}/slog_support.rs | 0 src/lib.rs | 10 ++----- 7 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/external/arbitrary_support.rs create mode 100644 src/external/mod.rs rename src/{ => external}/serde_support.rs (100%) rename src/{ => external}/slog_support.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 7f95eb9f..709d803e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -117,7 +117,6 @@ version = "2" [dependencies.arbitrary] optional = true version = "1" -features = ["derive"] # Public (unstable): Used in `zerocopy` derive [dependencies.zerocopy] diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs index 5d939e18..2233e003 100644 --- a/examples/windows_guid.rs +++ b/examples/windows_guid.rs @@ -53,10 +53,7 @@ fn guid_to_uuid() { #[cfg(windows)] fn uuid_from_cocreateguid() { use uuid::{Uuid, Variant, Version}; - use winapi::{ - shared::guiddef, - um::combaseapi::CoCreateGuid, - }; + use winapi::{shared::guiddef, um::combaseapi::CoCreateGuid}; let mut guid = guiddef::GUID::default(); diff --git a/src/external/arbitrary_support.rs b/src/external/arbitrary_support.rs new file mode 100644 index 00000000..7bec2547 --- /dev/null +++ b/src/external/arbitrary_support.rs @@ -0,0 +1,43 @@ +use crate::{std::convert::TryInto, Builder, Uuid}; + +use arbitrary::{Arbitrary, Unstructured}; + +impl Arbitrary<'_> for Uuid { + fn arbitrary(u: &mut Unstructured<'_>) -> arbitrary::Result { + let b = u + .bytes(16)? + .try_into() + .map_err(|_| arbitrary::Error::NotEnoughData)?; + + Ok(Builder::from_random_bytes(b).into_uuid()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + use crate::{Variant, Version}; + + #[test] + fn test_arbitrary() { + let mut bytes = Unstructured::new(&[ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + ]); + + let uuid = Uuid::arbitrary(&mut bytes).unwrap(); + + assert_eq!(Some(Version::Random), uuid.get_version()); + assert_eq!(Variant::RFC4122, uuid.get_variant()); + } + + #[test] + fn test_arbitrary_empty() { + let mut bytes = Unstructured::new(&[]); + + // Ensure we don't panic when building an arbitrary `Uuid` + let uuid = Uuid::arbitrary(&mut bytes); + + assert!(uuid.is_err()); + } +} diff --git a/src/external/mod.rs b/src/external/mod.rs new file mode 100644 index 00000000..8de6635b --- /dev/null +++ b/src/external/mod.rs @@ -0,0 +1,6 @@ +#[cfg(feature = "arbitrary")] +mod arbitrary_support; +#[cfg(feature = "serde")] +mod serde_support; +#[cfg(feature = "slog")] +mod slog_support; diff --git a/src/serde_support.rs b/src/external/serde_support.rs similarity index 100% rename from src/serde_support.rs rename to src/external/serde_support.rs diff --git a/src/slog_support.rs b/src/external/slog_support.rs similarity index 100% rename from src/slog_support.rs rename to src/external/slog_support.rs diff --git a/src/lib.rs b/src/lib.rs index 102be5ee..7e23d557 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -190,9 +190,6 @@ compile_error!("The `zerocopy-unstable` feature is unstable and may break betwee #[cfg(feature = "zerocopy-unstable")] use zerocopy::{AsBytes, FromBytes, Unaligned}; -#[cfg(feature = "arbitrary")] -use arbitrary::Arbitrary; - mod builder; mod error; mod parser; @@ -210,10 +207,8 @@ mod v5; #[cfg(feature = "rng")] mod rng; -#[cfg(feature = "serde")] -mod serde_support; -#[cfg(feature = "slog")] -mod slog_support; + +mod external; #[cfg(feature = "macros")] #[macro_use] @@ -359,7 +354,6 @@ pub enum Variant { feature = "zerocopy-unstable", derive(AsBytes, FromBytes, Unaligned) )] -#[cfg_attr(feature = "arbitrary", derive(Arbitrary))] #[repr(transparent)] pub struct Uuid(Bytes); From 69331012d4a1232d979e75095a053857e828f71e Mon Sep 17 00:00:00 2001 From: KodrAus Date: Tue, 2 Nov 2021 08:23:09 +1000 Subject: [PATCH 4/4] replace mailing list with discussions --- CONTRIBUTING.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 754fa27e..087f23d8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,8 +12,7 @@ Thank you for your interest in contributing to the Uuid Project! * [Out-of-tree Contributions](#out-of-tree-contributions) * [Helpful Links](#helpful-links) -For any questions, please make a post on [users.rust-lang.org][u-r-l-o], post -on [uuid-rs mailing list]. +For any questions, please make a post on [Discussions] or [users.rust-lang.org][u-r-l-o]. > All contributors need to follow our [Code of Conduct]. @@ -132,6 +131,5 @@ seasoned developers, some useful places to look for information are: [RFC 4122]: https://www.ietf.org/rfc/rfc4122.txt [u-r-l-o]: https://users.rust-lang.org -[uuid-rs mailing list]: https://uuid-rs.groups.io -[gitter]: https://gitter.im/uuid-rs/Lobby +[Discussions]: https://github.com/uuid-rs/uuid/discussions [search existing issues]: https://github.com/uuid-rs/uuid/search?q=&type=Issues&utf8=%E2%9C%93