From 236061811b556227cfe3a5585dbccc788296f7e1 Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 7 Feb 2024 10:12:13 +0100 Subject: Upgrade uuid to 1.7.0 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/rust/crates/uuid For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: If3618628314deef6e8dce2a301bd1dda4523ae24 --- .cargo_vcs_info.json | 2 +- Android.bp | 6 +- CODE_OF_CONDUCT.md | 78 ----- CONTRIBUTING.md | 140 -------- COPYRIGHT | 8 - Cargo.toml | 84 +++-- Cargo.toml.orig | 83 ++--- METADATA | 25 +- README.md | 14 +- benches/format_str.rs | 66 ---- benches/parse_str.rs | 50 --- benches/v4.rs | 11 - examples/random_uuid.rs | 15 - examples/sortable_uuid.rs | 15 - examples/uuid_macro.rs | 19 -- examples/windows_guid.rs | 112 ------- src/builder.rs | 6 +- src/external.rs | 2 + src/external/arbitrary_support.rs | 2 +- src/external/borsh_support.rs | 23 ++ src/fmt.rs | 10 + src/lib.rs | 493 +++++++++++++++++++++++------ src/macros.rs | 11 +- src/md5.rs | 2 +- src/parser.rs | 8 + src/timestamp.rs | 115 +++++-- src/v1.rs | 37 ++- src/v3.rs | 24 +- src/v4.rs | 24 +- src/v5.rs | 33 +- src/v6.rs | 43 ++- src/v7.rs | 44 ++- src/v8.rs | 15 +- tests/macros.rs | 11 - tests/ui/compile_fail/invalid_parse.rs | 45 --- tests/ui/compile_fail/invalid_parse.stderr | 197 ------------ tests/ui/compile_pass/renamed.rs | 11 - tests/ui/compile_pass/valid.rs | 20 -- 38 files changed, 831 insertions(+), 1073 deletions(-) delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 COPYRIGHT delete mode 100644 benches/format_str.rs delete mode 100644 benches/parse_str.rs delete mode 100644 benches/v4.rs delete mode 100644 examples/random_uuid.rs delete mode 100644 examples/sortable_uuid.rs delete mode 100644 examples/uuid_macro.rs delete mode 100644 examples/windows_guid.rs create mode 100644 src/external/borsh_support.rs delete mode 100644 tests/macros.rs delete mode 100644 tests/ui/compile_fail/invalid_parse.rs delete mode 100644 tests/ui/compile_fail/invalid_parse.stderr delete mode 100644 tests/ui/compile_pass/renamed.rs delete mode 100644 tests/ui/compile_pass/valid.rs diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 6175168..605a4fb 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "573362627c354bd13432e9aa9cdc3465e00aaff3" + "sha1": "cefc353334784f91f3cab97fa16bf7a1a141b800" }, "path_in_vcs": "" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index fe212f7..eb86c7e 100644 --- a/Android.bp +++ b/Android.bp @@ -32,7 +32,6 @@ license { "SPDX-license-identifier-MIT", ], license_text: [ - "COPYRIGHT", "LICENSE-APACHE", "LICENSE-MIT", ], @@ -43,12 +42,11 @@ rust_library { host_supported: true, crate_name: "uuid", cargo_env_compat: true, - cargo_pkg_version: "1.3.0", + cargo_pkg_version: "1.7.0", srcs: ["src/lib.rs"], edition: "2018", features: [ "atomic", - "getrandom", "rng", "serde", "std", @@ -72,7 +70,7 @@ rust_library_rlib { name: "libuuid_nostd", crate_name: "uuid", cargo_env_compat: true, - cargo_pkg_version: "1.3.0", + cargo_pkg_version: "1.7.0", srcs: ["src/lib.rs"], edition: "2018", apex_available: [ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 43ff03c..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,78 +0,0 @@ -# Contributor Covenant Code of Conduct - -The latest version of the CODE OF CONDUCT can be found [here]. - -[here]: https://github.com/uuid-rs/conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -education, socio-economic status, nationality, personal appearance, race, -religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or - advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting one of the project maintainers through details available -on their GitHub profile. All complaints will be reviewed and investigated and will -result in a response that is deemed necessary and appropriate to the circumstances. -The project team is obligated to maintain confidentiality with regard to the -reporter of an incident. Further details of specific enforcement policies may -be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html - -[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 1025171..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,140 +0,0 @@ -Contributing to Uuid ---- -[Contributing to Uuid]: #contributing-to-uuid - -Thank you for your interest in contributing to the Uuid Project! - -* [Feature Requests](#feature-requests) -* [Bug Reports](#bug-reports) -* [Pull Requests](#pull-requests) -* [Writing Documentation](#writing-documentation) -* [Issue Triage](#issue-triage) -* [Out-of-tree Contributions](#out-of-tree-contributions) -* [Helpful Links](#helpful-links) - -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]. - -[Code of Conduct]: CODE_OF_CONDUCT.md - -# Feature Requests -[Feature Requests]: #feature-requests - -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. - -File your feature request with a descriptive title, as this helps others find -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. 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 - -# Bug Reports -[Bug Reports]: #bug-reports - -While no one likes bugs, they are an unfortunate reality in software. Remember -we can't fix bugs we don't know about, so don't be shy about reporting. - -If you have the chance, please [search existing issues], as there is a chance -that someone has already reported your error. This isn't strictly needed, as -sometimes you might not what exactly you are looking for. - -File your issue with a descriptive title, as this helps others find your issue. - -Reporting a bug is as easy as following [this link][Bug Report Link] and -filling it in. - -Sometimes a backtrace may be needed. In that case, set `RUST_BACKTRACE` -environment variable to `1`. For example: - -```bash -$ RUST_BACKTRACE=1 cargo build -``` - -> We welcome pull requests for your own bug reports, provided they have been -discussed. - -[Bug Report Link]: https://github.com/uuid-rs/uuid/issues/new?template=Bug_report.md - -# Pull Requests -[Pull Requests]: #pull-requests - -Pull requests(PRs) are the primary mechanism we use to change Uuid. GitHub itself -has some [great documentation] on using the Pull Request feature. We use the -"fork and pull" model described [here][fnp], where contributors push changes to -their personal fork and create pull requests to bring those changes into the -source repository. - -Unless the changes are fairly minor (like documentation changes or tiny -patches), we require PRs to relevant issues. - -Please open PRs against the `main` branch. - -When you feel that the PR is ready, please ping one of the maintainers so -they can review your changes. - -[great documentation]: https://help.github.com/articles/about-pull-requests/ -[fnp]: https://help.github.com/articles/about-collaborative-development-models/ - -# Writing Documentation -[Writing Documentation]: #writing-documentation - -Documentation is an important part of Uuid. Lackluster or incorrect -documentation can cause headaches for the users of `uuid`. Therefore, -improvements to documentation are always welcome. - -We follow the documentation style guidelines as given by [RFC 1574]. - -[RFC 1574]: https://github.com/rust-lang/rfcs/blob/main/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text - -# Issue Triage -[Issue Triage]: #issue-triage - -Sometimes, an issue might stay open even after the relevant bug has been fixed. -Other times, the bug report may become invalid. Or we may just forget about the -bug. - -You can help to go through old bug reports and check if they are still valid. -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 - -# Fuzzing -We use [`cargo fuzz`] to fuzz test various parts of `uuid`. See their guide -for more details on what fuzzing is and how to run the tests yourself. - -# Helpful Links -[Helpful Links]: #helpful-links - -For people new to Uuid, and just starting to contribute, or even for more -seasoned developers, some useful places to look for information are: - -* The Wikipedia entry on [Universally Unique Identifier][wiki-uuid]. -* [RFC 4122] which gives the specification of Uuids. - -[wiki-uuid]: https://en.wikipedia.org/wiki/Universally_unique_identifier -[RFC 4122]: https://www.ietf.org/rfc/rfc4122.txt - -[u-r-l-o]: https://users.rust-lang.org -[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 -[`cargo fuzz`]: https://rust-fuzz.github.io/book/cargo-fuzz.html diff --git a/COPYRIGHT b/COPYRIGHT deleted file mode 100644 index 925929c..0000000 --- a/COPYRIGHT +++ /dev/null @@ -1,8 +0,0 @@ -The Uuid Project is copyright 2013-2014, The Rust Project Developers and -copyright 2018, The Uuid Developers. - -Licensed under the Apache License, Version 2.0 or the MIT License , at your option. All files in the project -carrying such notice may not be copied, modified, or distributed except -according to those terms. diff --git a/Cargo.toml b/Cargo.toml index e07072c..320fd4c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,21 @@ [package] edition = "2018" +rust-version = "1.60.0" name = "uuid" -version = "1.3.0" +version = "1.7.0" authors = [ "Ashley Mannix", "Christopher Armstrong", "Dylan DPC", "Hunar Roop Kahlon", ] -exclude = [".github/**"] +include = [ + "src", + "README.md", + "LICENSE-APACHE", + "LICENSE-MIT", +] description = "A library to generate and parse UUIDs." homepage = "https://github.com/uuid-rs/uuid" documentation = "https://docs.rs/uuid" @@ -39,19 +45,11 @@ license = "Apache-2.0 OR MIT" repository = "https://github.com/uuid-rs/uuid" [package.metadata.docs.rs] -rustc-args = [ - "--cfg", - "uuid_unstable", -] -rustdoc-args = [ - "--cfg", - "uuid_unstable", -] -targets = ["x86_64-unknown-linux-gnu"] features = [ "serde", "arbitrary", "slog", + "borsh", "v1", "v3", "v4", @@ -60,6 +58,15 @@ features = [ "v7", "v8", ] +rustc-args = [ + "--cfg", + "uuid_unstable", +] +rustdoc-args = [ + "--cfg", + "uuid_unstable", +] +targets = ["x86_64-unknown-linux-gnu"] [package.metadata.playground] features = [ @@ -81,23 +88,34 @@ optional = true version = "0.5" optional = true default-features = false -package = "atomic" + +[dependencies.borsh] +version = "1" +optional = true +default-features = false + +[dependencies.borsh-derive] +version = "1" +optional = true +default-features = false + +[dependencies.bytemuck] +version = "1.14.0" +features = ["derive"] +optional = true [dependencies.getrandom] version = "0.2" optional = true -package = "getrandom" [dependencies.md-5] version = "0.10" optional = true default-features = false -package = "md-5" [dependencies.rand] version = "0.8" optional = true -package = "rand" [dependencies.serde] version = "1.0.56" @@ -108,21 +126,18 @@ default-features = false version = "1" optional = true default-features = false -package = "sha1_smol" [dependencies.slog] version = "2" optional = true [dependencies.uuid-macro-internal] -version = "1.3.0" +version = "1.7.0" optional = true -package = "uuid-macro-internal" [dependencies.wasm-bindgen] version = "0.2" optional = true -package = "wasm-bindgen" [dependencies.zerocopy] version = "0.6" @@ -147,20 +162,24 @@ version = "1.0.56" version = "1.0.52" [features] +atomic = ["dep:atomic"] +borsh = [ + "dep:borsh", + "dep:borsh-derive", +] default = ["std"] fast-rng = [ "rng", - "rand", + "dep:rand", ] js = [ - "wasm-bindgen", - "getrandom", - "getrandom/js", + "dep:wasm-bindgen", + "getrandom?/js", ] -macro-diagnostics = ["uuid-macro-internal"] -md5 = ["md-5"] -rng = ["getrandom"] -sha1 = ["sha1_smol"] +macro-diagnostics = ["dep:uuid-macro-internal"] +md5 = ["dep:md-5"] +rng = ["dep:getrandom"] +sha1 = ["dep:sha1_smol"] std = [] v1 = ["atomic"] v3 = ["md5"] @@ -173,16 +192,11 @@ v7 = [ ] v8 = [] -[target."cfg(target_arch = \"wasm32\")".dev-dependencies.wasm-bindgen] -version = "0.2" -package = "wasm-bindgen" - -[target."cfg(target_arch = \"wasm32\")".dev-dependencies.wasm-bindgen-test] +[target."cfg(all(target_arch = \"wasm32\", target_vendor = \"unknown\", target_os = \"unknown\"))".dev-dependencies.wasm-bindgen-test] version = "0.3" -[target."cfg(windows)".dev-dependencies.windows-sys] -version = "0.45.0" -features = ["Win32_System_Com"] +[target."cfg(target = \"wasm32-unknown-unknown\")".dev-dependencies.wasm-bindgen] +version = "0.2" [badges.is-it-maintained-issue-resolution] repository = "uuid-rs/uuid" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index e4421b5..b09ca68 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -14,8 +14,11 @@ categories = [ description = "A library to generate and parse UUIDs." documentation = "https://docs.rs/uuid" edition = "2018" -exclude = [ - ".github/**" +include = [ + "src", + "README.md", + "LICENSE-APACHE", + "LICENSE-MIT", ] keywords = [ "guid", @@ -27,13 +30,14 @@ homepage = "https://github.com/uuid-rs/uuid" name = "uuid" readme = "README.md" repository = "https://github.com/uuid-rs/uuid" -version = "1.3.0" # remember to update html_root_url in lib.rs +version = "1.7.0" # remember to update html_root_url in lib.rs +rust-version = "1.60.0" [package.metadata.docs.rs] rustc-args = ["--cfg", "uuid_unstable"] rustdoc-args = ["--cfg", "uuid_unstable"] targets = ["x86_64-unknown-linux-gnu"] -features = ["serde", "arbitrary", "slog", "v1", "v3", "v4", "v5", "v6", "v7", "v8"] +features = ["serde", "arbitrary", "slog", "borsh", "v1", "v3", "v4", "v5", "v6", "v7", "v8"] [package.metadata.playground] features = ["serde", "v1", "v3", "v4", "v5", "v6", "v7", "v8"] @@ -50,9 +54,9 @@ status = "actively-developed" [features] default = ["std"] std = [] -macro-diagnostics = ["uuid-macro-internal"] +macro-diagnostics = ["dep:uuid-macro-internal"] -# NOTE: When adding new features, check the `ci.yml` workflow .. +# NOTE: When adding new features, check the `ci.yml` workflow # and include them where necessary (you can follow along with existing features) v1 = ["atomic"] v3 = ["md5"] @@ -62,13 +66,22 @@ v6 = ["atomic"] v7 = ["atomic", "rng"] v8 = [] -js = ["wasm-bindgen", "getrandom", "getrandom/js"] +js = ["dep:wasm-bindgen", "getrandom?/js"] -rng = ["getrandom"] -fast-rng = ["rng", "rand"] +rng = ["dep:getrandom"] +fast-rng = ["rng", "dep:rand"] -sha1 = ["sha1_smol"] -md5 = ["md-5"] +sha1 = ["dep:sha1_smol"] +md5 = ["dep:md-5"] +atomic = ["dep:atomic"] + +borsh = ["dep:borsh", "dep:borsh-derive"] + +# Public: Used in trait impls on `Uuid` +[dependencies.bytemuck] +version = "1.14.0" +optional = true +features = ["derive"] # Public: Used in trait impls on `Uuid` [dependencies.serde] @@ -95,57 +108,56 @@ version = "1.1.3" optional = true version = "0.6" +# Public: Used in trait impls on `Uuid` +[dependencies.borsh] +optional = true +version = "1" +default-features = false + # Private -# Don't depend on this optional feature directly: it may change at any time -# use the `rng` feature instead +[dependencies.borsh-derive] +optional = true +version = "1" +default-features = false + +# Public +# Usage of `getrandom`'s pluggable randomness for custom targets is documented +# in `uuid`'s library docs [dependencies.getrandom] -package = "getrandom" optional = true version = "0.2" # Private -# Don't depend on this optional feature directly: it may change at any time -# use the `fast-rng` feature instead [dependencies.rand] -package = "rand" optional = true version = "0.8" # Private -# Don't depend on this optional feature directly: it may change at any time -# Use the `md5` feature instead [dependencies.md-5] -package = "md-5" default-features = false optional = true version = "0.10" # Private -# Don't depend on this optional feature directly: it may change at any time -# Use the `sha1` feature instead [dependencies.sha1_smol] -package = "sha1_smol" default-features = false optional = true version = "1" # Public: Re-exported -# Don't depend on this optional feature directly: it may change at any time -# Use the `macro-diagnostics` feature instead [dependencies.uuid-macro-internal] -package = "uuid-macro-internal" -version = "1.3.0" +version = "1.7.0" path = "macros" optional = true +# Private [dependencies.atomic] -package = "atomic" default-features = false optional = true version = "0.5" +# Private [dependencies.wasm-bindgen] -package = "wasm-bindgen" version = "0.2" optional = true @@ -161,11 +173,10 @@ version = "1.0" [dev-dependencies.serde_test] version = "1.0.56" -[target.'cfg(target_arch = "wasm32")'.dev-dependencies.wasm-bindgen] -package = "wasm-bindgen" +[target.'cfg(target = "wasm32-unknown-unknown")'.dev-dependencies.wasm-bindgen] version = "0.2" -[target.'cfg(target_arch = "wasm32")'.dev-dependencies.wasm-bindgen-test] +[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"))'.dev-dependencies.wasm-bindgen-test] version = "0.3" [dev-dependencies.trybuild] @@ -174,11 +185,9 @@ version = "1.0.52" [dev-dependencies.rustversion] version = "1" -[target.'cfg(windows)'.dev-dependencies.windows-sys] -version = "0.45.0" -features = ["Win32_System_Com"] - [workspace] members = [ - "macros" + "macros", + "examples", + "tests/smoke-test", ] diff --git a/METADATA b/METADATA index dbb7b95..51da58e 100644 --- a/METADATA +++ b/METADATA @@ -1,23 +1,20 @@ # This project was upgraded with external_updater. -# Usage: tools/external_updater/updater.sh update rust/crates/uuid -# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md +# Usage: tools/external_updater/updater.sh update external/rust/crates/uuid +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "uuid" description: "A library to generate and parse UUIDs." third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/uuid" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/uuid/uuid-1.3.0.crate" - } - version: "1.3.0" license_type: NOTICE last_upgrade_date { - year: 2023 - month: 3 - day: 29 + year: 2024 + month: 2 + day: 7 + } + homepage: "https://crates.io/crates/uuid" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/uuid/uuid-1.7.0.crate" + version: "1.7.0" } } diff --git a/README.md b/README.md index 70a0799..a1aba43 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # `uuid` [![Latest Version](https://img.shields.io/crates/v/uuid.svg)](https://crates.io/crates/uuid) -![Minimum rustc version](https://img.shields.io/badge/rustc-1.46.0+-yellow.svg) [![Continuous integration](https://github.com/uuid-rs/uuid/actions/workflows/ci.yml/badge.svg)](https://github.com/uuid-rs/uuid/actions/workflows/ci.yml) Here's an example of a UUID: @@ -29,7 +28,7 @@ Add the following to your `Cargo.toml`: ```toml [dependencies.uuid] -version = "1.3.0" +version = "1.7.0" features = [ "v4", # Lets you generate random UUIDs "fast-rng", # Use a faster (but still sufficiently random) RNG @@ -66,16 +65,11 @@ assert_eq!(Some(Version::Random), my_uuid.get_version()); If you'd like to parse UUIDs _really_ fast, check out the [`uuid-simd`](https://github.com/nugine/uuid-simd) library. -For more details on using `uuid`, [see the library documentation](https://docs.rs/uuid/1.3.0/uuid). - -## Minimum Supported Rust Version (MSRV) - -The minimum supported Rust version for `uuid` is documented in -CI. It may be bumped in minor releases as necessary. +For more details on using `uuid`, [see the library documentation](https://docs.rs/uuid/1.7.0/uuid). ## References -* [`uuid` library docs](https://docs.rs/uuid/1.3.0/uuid). +* [`uuid` library docs](https://docs.rs/uuid/1.7.0/uuid). * [Wikipedia: Universally Unique Identifier](http://en.wikipedia.org/wiki/Universally_unique_identifier). * [RFC4122: A Universally Unique IDentifier (UUID) URN Namespace](http://tools.ietf.org/html/rfc4122). @@ -96,4 +90,4 @@ at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall -be dual licensed as above, without any additional terms or conditions. \ No newline at end of file +be dual licensed as above, without any additional terms or conditions. diff --git a/benches/format_str.rs b/benches/format_str.rs deleted file mode 100644 index fab8929..0000000 --- a/benches/format_str.rs +++ /dev/null @@ -1,66 +0,0 @@ -#![feature(test)] -extern crate test; - -use std::io::Write; -use test::Bencher; -use uuid::Uuid; - -#[bench] -fn hyphenated(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 36]; - write!(&mut buffer as &mut [_], "{:x}", uuid.hyphenated()).unwrap(); - buffer - }); -} - -#[bench] -fn simple(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 32]; - write!(&mut buffer as &mut [_], "{:x}", uuid.simple()).unwrap(); - buffer - }) -} - -#[bench] -fn urn(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 36 + 9]; - write!(&mut buffer as &mut [_], "{:x}", uuid.urn()).unwrap(); - buffer - }) -} - -#[bench] -fn encode_hyphen(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 36]; - uuid.hyphenated().encode_lower(&mut buffer); - buffer - }); -} - -#[bench] -fn encode_simple(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 32]; - uuid.simple().encode_lower(&mut buffer); - buffer - }) -} - -#[bench] -fn encode_urn(b: &mut Bencher) { - let uuid = Uuid::parse_str("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4").unwrap(); - b.iter(|| { - let mut buffer = [0_u8; 36 + 9]; - uuid.urn().encode_lower(&mut buffer); - buffer - }) -} diff --git a/benches/parse_str.rs b/benches/parse_str.rs deleted file mode 100644 index e53ba24..0000000 --- a/benches/parse_str.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![feature(test)] -extern crate test; - -use test::Bencher; -use uuid::Uuid; - -#[bench] -fn parse_nil(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("00000000000000000000000000000000")); -} - -#[bench] -fn parse_nil_hyphenated(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("00000000-0000-0000-0000-000000000000")); -} - -#[bench] -fn parse_random(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("67e5504410b1426f9247bb680e5fe0c8")); -} - -#[bench] -fn parse_random_hyphenated(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8")); -} - -#[bench] -fn parse_urn(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8")); -} - -#[bench] -fn parse_invalid_len(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4")) -} - -#[bench] -fn parse_invalid_character(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4")) -} - -#[bench] -fn parse_invalid_group_len(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("01020304-1112-2122-3132-41424344")); -} - -#[bench] -fn parse_invalid_groups(b: &mut Bencher) { - b.iter(|| Uuid::parse_str("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4")); -} diff --git a/benches/v4.rs b/benches/v4.rs deleted file mode 100644 index 61c3246..0000000 --- a/benches/v4.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![cfg(feature = "v4")] -#![feature(test)] -extern crate test; - -use test::Bencher; -use uuid::Uuid; - -#[bench] -fn new_v4(b: &mut Bencher) { - b.iter(|| Uuid::new_v4()); -} diff --git a/examples/random_uuid.rs b/examples/random_uuid.rs deleted file mode 100644 index 897071c..0000000 --- a/examples/random_uuid.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Generating a random UUID. -//! -//! If you enable the `v4` feature you can generate random UUIDs. - -#[test] -#[cfg(feature = "v4")] -fn generate_random_uuid() { - use uuid::Uuid; - - let uuid = Uuid::new_v4(); - - assert_eq!(Some(uuid::Version::Random), uuid.get_version()); -} - -fn main() {} diff --git a/examples/sortable_uuid.rs b/examples/sortable_uuid.rs deleted file mode 100644 index dc12812..0000000 --- a/examples/sortable_uuid.rs +++ /dev/null @@ -1,15 +0,0 @@ -//! Generating a sortable UUID. -//! -//! If you enable the `v7` feature you can generate sortable UUIDs. - -#[test] -#[cfg(feature = "v7")] -fn generate_sortable_uuid() { - use uuid::Uuid; - - let uuid = Uuid::now_v7(); - - assert_eq!(Some(uuid::Version::SortRand), uuid.get_version()); -} - -fn main() {} diff --git a/examples/uuid_macro.rs b/examples/uuid_macro.rs deleted file mode 100644 index c4ff048..0000000 --- a/examples/uuid_macro.rs +++ /dev/null @@ -1,19 +0,0 @@ -//! Using the `uuid!` macro. -//! -//! `uuid!` will parse encoded UUIDs at compile time instead of at runtime. -//! If you've got a fixed UUID string handy then consider using `uuid!` instead -//! of `Uuid::parse_str` or `str::parse`. -//! -//! If you enable the `macro-diagnostics` feature, you can see much better -//! error messages. - -#[test] -fn parse_uuid_at_compile_time() { - use uuid::uuid; - - let uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"); - - assert_eq!(Some(uuid::Version::Random), uuid.get_version()); -} - -fn main() {} diff --git a/examples/windows_guid.rs b/examples/windows_guid.rs deleted file mode 100644 index 6cbc10e..0000000 --- a/examples/windows_guid.rs +++ /dev/null @@ -1,112 +0,0 @@ -//! Converting between Windows GUIDs and UUIDs. -//! -//! Windows GUIDs are specified as using mixed endianness. -//! What you get will depend on the source of the GUID. -//! Functions like `CoCreateGuid` will generate a valid UUID so -//! the fields will be naturally ordered for `Uuid::from_fields`. -//! Other GUIDs might need to be passed to `Uuid::from_fields_le` -//! to have their ordering swapped. - -#[test] -#[cfg(windows)] -fn guid_to_uuid() { - use uuid::Uuid; - use windows_sys::core; - - let guid_in = core::GUID { - data1: 0x4a35229d, - data2: 0x5527, - data3: 0x4f30, - data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], - }; - - let uuid = Uuid::from_fields(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); - - let guid_out = { - let fields = uuid.as_fields(); - - core::GUID { - data1: fields.0, - data2: fields.1, - data3: fields.2, - data4: *fields.3, - } - }; - - assert_eq!( - (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), - ( - guid_out.data1, - guid_out.data2, - guid_out.data3, - guid_out.data4 - ) - ); -} - -#[test] -#[cfg(windows)] -fn guid_to_uuid_le_encoded() { - use uuid::Uuid; - use windows_sys::core; - - // A GUID might not be encoded directly as a UUID - // If its fields are stored in little-endian order they might - // need to be flipped. Whether or not this is necessary depends - // on the source of the GUID - let guid_in = core::GUID { - data1: 0x9d22354a, - data2: 0x2755, - data3: 0x304f, - data4: [0x86, 0x47, 0x9d, 0xc5, 0x4e, 0x1e, 0xe1, 0xe8], - }; - - let uuid = Uuid::from_fields_le(guid_in.data1, guid_in.data2, guid_in.data3, &guid_in.data4); - - let guid_out = { - let fields = uuid.to_fields_le(); - - core::GUID { - data1: fields.0, - data2: fields.1, - data3: fields.2, - data4: *fields.3, - } - }; - - assert_eq!( - (guid_in.data1, guid_in.data2, guid_in.data3, guid_in.data4), - ( - guid_out.data1, - guid_out.data2, - guid_out.data3, - guid_out.data4 - ) - ); -} - -#[test] -#[cfg(windows)] -fn uuid_from_cocreateguid() { - use uuid::{Uuid, Variant, Version}; - use windows_sys::core; - use windows_sys::Win32::System::Com::CoCreateGuid; - - let mut guid = core::GUID { - data1: 0, - data2: 0, - data3: 0, - data4: [0u8; 8], - }; - - unsafe { - CoCreateGuid(&mut guid); - } - - let uuid = Uuid::from_fields(guid.data1, guid.data2, guid.data3, &guid.data4); - - assert_eq!(Variant::RFC4122, uuid.get_variant()); - assert_eq!(Some(Version::Random), uuid.get_version()); -} - -fn main() {} diff --git a/src/builder.rs b/src/builder.rs index 60aeb43..2dd68a2 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -95,7 +95,6 @@ impl Uuid { /// uuid.hyphenated().to_string(), /// ); /// ``` - #[cfg(uuid_unstable)] pub const fn max() -> Self { Uuid::from_bytes([0xFF; 16]) } @@ -412,6 +411,7 @@ impl Uuid { /// # Ok(()) /// # } /// ``` + #[inline] pub const fn from_bytes(bytes: Bytes) -> Uuid { Uuid(bytes) } @@ -480,6 +480,7 @@ impl Uuid { /// # Ok(()) /// # } /// ``` + #[inline] pub fn from_bytes_ref(bytes: &Bytes) -> &Uuid { // SAFETY: `Bytes` and `Uuid` have the same ABI unsafe { &*(bytes as *const Bytes as *const Uuid) } @@ -598,7 +599,6 @@ impl Builder { /// Creates a `Builder` for a version 6 UUID using the supplied timestamp and node ID. /// /// This method will encode the ticks, counter, and node ID in a sortable UUID. - #[cfg(uuid_unstable)] pub const fn from_sorted_rfc4122_timestamp( ticks: u64, counter: u16, @@ -636,7 +636,6 @@ impl Builder { /// # Ok(()) /// # } /// ``` - #[cfg(uuid_unstable)] pub const fn from_unix_timestamp_millis(millis: u64, random_bytes: &[u8; 10]) -> Self { Builder(timestamp::encode_unix_timestamp_millis( millis, @@ -648,7 +647,6 @@ impl Builder { /// /// This method won't interpret the given bytes in any way, except to set the appropriate /// bits for the UUID version and variant. - #[cfg(uuid_unstable)] pub const fn from_custom_bytes(custom_bytes: Bytes) -> Self { Builder::from_bytes(custom_bytes) .with_variant(Variant::RFC4122) diff --git a/src/external.rs b/src/external.rs index 219a923..6f20d8f 100644 --- a/src/external.rs +++ b/src/external.rs @@ -1,5 +1,7 @@ #[cfg(feature = "arbitrary")] pub(crate) mod arbitrary_support; +#[cfg(feature = "borsh")] +pub(crate) mod borsh_support; #[cfg(feature = "serde")] pub(crate) mod serde_support; #[cfg(feature = "slog")] diff --git a/src/external/arbitrary_support.rs b/src/external/arbitrary_support.rs index 38cce7c..40c11f5 100644 --- a/src/external/arbitrary_support.rs +++ b/src/external/arbitrary_support.rs @@ -12,7 +12,7 @@ impl Arbitrary<'_> for Uuid { Ok(Builder::from_random_bytes(b).into_uuid()) } - fn size_hint(depth: usize) -> (usize, Option) { + fn size_hint(_: usize) -> (usize, Option) { (16, Some(16)) } } diff --git a/src/external/borsh_support.rs b/src/external/borsh_support.rs new file mode 100644 index 0000000..f6f93c7 --- /dev/null +++ b/src/external/borsh_support.rs @@ -0,0 +1,23 @@ +#[cfg(test)] +mod borsh_tests { + use crate::Uuid; + use std::string::ToString; + + #[test] + fn test_serialize() { + let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4"; + let uuid = Uuid::parse_str(uuid_str).unwrap(); + let uuid_bytes = uuid.as_bytes().to_vec(); + let borsh_bytes = borsh::to_vec(&uuid).unwrap(); + assert_eq!(uuid_bytes, borsh_bytes); + } + + #[test] + fn test_deserialize() { + let uuid_str = "f9168c5e-ceb2-4faa-b6bf-329bf39fa1e4"; + let uuid = Uuid::parse_str(uuid_str).unwrap(); + let uuid_bytes = uuid.as_bytes().to_vec(); + let deserialized = borsh::from_slice::(&uuid_bytes).unwrap().to_string(); + assert_eq!(uuid_str, deserialized); + } +} diff --git a/src/fmt.rs b/src/fmt.rs index 92b4042..1dda31b 100644 --- a/src/fmt.rs +++ b/src/fmt.rs @@ -16,6 +16,9 @@ use crate::{ Uuid, Variant, }; +#[cfg(feature = "std")] +use crate::std::string::{String, ToString}; + impl std::fmt::Debug for Uuid { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -29,6 +32,13 @@ impl fmt::Display for Uuid { } } +#[cfg(feature = "std")] +impl From for String { + fn from(uuid: Uuid) -> Self { + uuid.to_string() + } +} + impl fmt::Display for Variant { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { diff --git a/src/lib.rs b/src/lib.rs index 05ebc2d..4c3c9b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,7 +39,7 @@ //! //! ```toml //! [dependencies.uuid] -//! version = "1.3.0" +//! version = "1.7.0" //! features = [ //! "v4", # Lets you generate random UUIDs //! "fast-rng", # Use a faster (but still sufficiently random) RNG @@ -80,6 +80,9 @@ //! * `v3` - Version 3 UUIDs based on the MD5 hash of some data. //! * `v4` - Version 4 UUIDs with random data. //! * `v5` - Version 5 UUIDs based on the SHA1 hash of some data. +//! * `v6` - Version 6 UUIDs using a timestamp and monotonic counter. +//! * `v7` - Version 7 UUIDs using a Unix timestamp. +//! * `v8` - Version 8 UUIDs using user-defined data. //! //! Versions that are in draft are also supported. See the _unstable features_ section for details. //! @@ -103,20 +106,20 @@ //! * `macro-diagnostics` - enhances the diagnostics of `uuid!` macro. //! * `serde` - adds the ability to serialize and deserialize a UUID using //! `serde`. +//! * `borsh` - adds the ability to serialize and deserialize a UUID using +//! `borsh`. //! * `arbitrary` - adds an `Arbitrary` trait implementation to `Uuid` for //! fuzzing. //! * `fast-rng` - 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. +//! * `bytemuck` - adds a `Pod` trait implementation to `Uuid` for byte manipulation //! //! # Unstable features //! //! Some features are unstable. They may be incomplete or depend on other //! unstable libraries. These include: //! -//! * `v6` - Version 6 UUIDs using a timestamp and monotonic counter. -//! * `v7` - Version 7 UUIDs using a Unix timestamp. -//! * `v8` - Version 8 UUIDs using user-defined data. //! * `zerocopy` - adds support for zero-copy deserialization using the //! `zerocopy` library. //! @@ -138,7 +141,7 @@ //! //! ```toml //! [dependencies.uuid] -//! version = "1.3.0" +//! version = "1.7.0" //! features = [ //! "v4", //! "v7", @@ -153,7 +156,7 @@ //! //! ```toml //! [dependencies.uuid] -//! version = "1.3.0" +//! version = "1.7.0" //! default-features = false //! ``` //! @@ -166,7 +169,7 @@ //! follow [`getrandom`'s docs] on configuring a source of randomness //! on currently unsupported targets. Alternatively, you can produce //! random bytes yourself and then pass them to [`Builder::from_random_bytes`] -//! without enabling the `v4` feature. +//! without enabling the `v4` or `v7` features. //! //! # Examples //! @@ -211,7 +214,7 @@ #![doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://docs.rs/uuid/1.3.0" + html_root_url = "https://docs.rs/uuid/1.7.0" )] #[cfg(any(feature = "std", test))] @@ -248,11 +251,11 @@ mod v3; mod v4; #[cfg(feature = "v5")] mod v5; -#[cfg(all(uuid_unstable, feature = "v6"))] +#[cfg(feature = "v6")] mod v6; -#[cfg(all(uuid_unstable, feature = "v7"))] +#[cfg(feature = "v7")] mod v7; -#[cfg(all(uuid_unstable, feature = "v8"))] +#[cfg(feature = "v8")] mod v8; #[cfg(feature = "md5")] @@ -271,6 +274,11 @@ mod macros; #[cfg(feature = "macro-diagnostics")] pub extern crate uuid_macro_internal; +#[doc(hidden)] +pub mod __macro_support { + pub use crate::std::result::Result::{Err, Ok}; +} + use crate::std::convert; pub use crate::{builder::Builder, error::Error}; @@ -304,16 +312,12 @@ pub enum Version { /// Version 5: SHA-1 hash. Sha1 = 5, /// Version 6: Sortable Timestamp and node ID. - #[cfg(uuid_unstable)] SortMac = 6, /// Version 7: Timestamp and random. - #[cfg(uuid_unstable)] SortRand = 7, /// Version 8: Custom. - #[cfg(uuid_unstable)] Custom = 8, /// The "max" (all ones) UUID. - #[cfg(uuid_unstable)] Max = 0xff, } @@ -431,8 +435,19 @@ pub enum Variant { /// /// The `Uuid` type is always guaranteed to be have the same ABI as [`Bytes`]. #[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[cfg_attr(all(uuid_unstable, feature = "zerocopy"), derive(AsBytes, FromBytes, Unaligned))] +#[cfg_attr( + all(uuid_unstable, feature = "zerocopy"), + derive(AsBytes, FromBytes, Unaligned) +)] +#[cfg_attr( + feature = "borsh", + derive(borsh_derive::BorshDeserialize, borsh_derive::BorshSerialize) +)] #[repr(transparent)] +#[cfg_attr( + feature = "bytemuck", + derive(bytemuck::Zeroable, bytemuck::Pod, bytemuck::TransparentWrapper) +)] pub struct Uuid(Bytes); impl Uuid { @@ -556,13 +571,9 @@ impl Uuid { 3 => Some(Version::Md5), 4 => Some(Version::Random), 5 => Some(Version::Sha1), - #[cfg(uuid_unstable)] 6 => Some(Version::SortMac), - #[cfg(uuid_unstable)] 7 => Some(Version::SortRand), - #[cfg(uuid_unstable)] 8 => Some(Version::Custom), - #[cfg(uuid_unstable)] 0xf => Some(Version::Max), _ => None, } @@ -687,22 +698,7 @@ impl Uuid { /// # } /// ``` pub const fn as_u128(&self) -> u128 { - (self.as_bytes()[0] as u128) << 120 - | (self.as_bytes()[1] as u128) << 112 - | (self.as_bytes()[2] as u128) << 104 - | (self.as_bytes()[3] as u128) << 96 - | (self.as_bytes()[4] as u128) << 88 - | (self.as_bytes()[5] as u128) << 80 - | (self.as_bytes()[6] as u128) << 72 - | (self.as_bytes()[7] as u128) << 64 - | (self.as_bytes()[8] as u128) << 56 - | (self.as_bytes()[9] as u128) << 48 - | (self.as_bytes()[10] as u128) << 40 - | (self.as_bytes()[11] as u128) << 32 - | (self.as_bytes()[12] as u128) << 24 - | (self.as_bytes()[13] as u128) << 16 - | (self.as_bytes()[14] as u128) << 8 - | (self.as_bytes()[15] as u128) + u128::from_be_bytes(*self.as_bytes()) } /// Returns a 128bit little-endian value containing the value. @@ -731,22 +727,7 @@ impl Uuid { /// # } /// ``` pub const fn to_u128_le(&self) -> u128 { - (self.as_bytes()[0] as u128) - | (self.as_bytes()[1] as u128) << 8 - | (self.as_bytes()[2] as u128) << 16 - | (self.as_bytes()[3] as u128) << 24 - | (self.as_bytes()[4] as u128) << 32 - | (self.as_bytes()[5] as u128) << 40 - | (self.as_bytes()[6] as u128) << 48 - | (self.as_bytes()[7] as u128) << 56 - | (self.as_bytes()[8] as u128) << 64 - | (self.as_bytes()[9] as u128) << 72 - | (self.as_bytes()[10] as u128) << 80 - | (self.as_bytes()[11] as u128) << 88 - | (self.as_bytes()[12] as u128) << 96 - | (self.as_bytes()[13] as u128) << 104 - | (self.as_bytes()[14] as u128) << 112 - | (self.as_bytes()[15] as u128) << 120 + u128::from_le_bytes(*self.as_bytes()) } /// Returns two 64bit values containing the value. @@ -799,6 +780,7 @@ impl Uuid { /// &bytes1 as *const [u8; 16] as *const u8, /// )); /// ``` + #[inline] pub const fn as_bytes(&self) -> &Bytes { &self.0 } @@ -818,6 +800,7 @@ impl Uuid { /// let uuid = Uuid::from_bytes(bytes); /// assert_eq!(bytes, uuid.into_bytes()); /// ``` + #[inline] pub const fn into_bytes(self) -> Bytes { self.0 } @@ -860,7 +843,6 @@ impl Uuid { } /// Tests if the UUID is max (all ones). - #[cfg(uuid_unstable)] pub const fn is_max(&self) -> bool { self.as_u128() == u128::MAX } @@ -920,13 +902,11 @@ impl Uuid { Some(Timestamp::from_rfc4122(ticks, counter)) } - #[cfg(uuid_unstable)] Some(Version::SortMac) => { let (ticks, counter) = timestamp::decode_sorted_rfc4122_timestamp(self); Some(Timestamp::from_rfc4122(ticks, counter)) } - #[cfg(uuid_unstable)] Some(Version::SortRand) => { let millis = timestamp::decode_unix_timestamp_millis(self); @@ -959,6 +939,22 @@ impl AsRef<[u8]> for Uuid { } } +#[cfg(feature = "std")] +impl From for std::vec::Vec { + fn from(value: Uuid) -> Self { + value.0.to_vec() + } +} + +#[cfg(feature = "std")] +impl std::convert::TryFrom> for Uuid { + type Error = Error; + + fn try_from(value: std::vec::Vec) -> Result { + Uuid::from_slice(&value) + } +} + #[cfg(feature = "serde")] pub mod serde { //! Adapters for alternative `serde` formats. @@ -976,7 +972,11 @@ mod tests { use crate::std::string::{String, ToString}; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; macro_rules! check { @@ -1003,7 +1003,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_compare() { let uuid1 = new(); let uuid2 = new2(); @@ -1016,7 +1023,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_default() { let default_uuid = Uuid::default(); let nil_uuid = Uuid::nil(); @@ -1025,7 +1039,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_display() { use crate::std::fmt::Write; @@ -1041,7 +1062,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_lowerhex() { use crate::std::fmt::Write; @@ -1055,7 +1083,14 @@ mod tests { // noinspection RsAssertEqual #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_operator_eq() { let uuid1 = new(); let uuid1_dup = uuid1.clone(); @@ -1072,7 +1107,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_uuid_to_string() { use crate::std::fmt::Write; @@ -1088,7 +1130,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_non_conforming() { let from_bytes = Uuid::from_bytes([4, 54, 67, 12, 43, 2, 2, 76, 32, 50, 87, 5, 1, 33, 43, 87]); @@ -1097,7 +1146,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_nil() { let nil = Uuid::nil(); let not_nil = new(); @@ -1108,12 +1164,23 @@ mod tests { assert_eq!(nil.get_version(), Some(Version::Nil)); assert_eq!(not_nil.get_version(), Some(Version::Random)); - assert_eq!(nil, Builder::from_bytes([0; 16]).with_version(Version::Nil).into_uuid()); + assert_eq!( + nil, + Builder::from_bytes([0; 16]) + .with_version(Version::Nil) + .into_uuid() + ); } #[test] - #[cfg(uuid_unstable)] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_max() { let max = Uuid::max(); let not_max = new(); @@ -1124,11 +1191,23 @@ mod tests { assert_eq!(max.get_version(), Some(Version::Max)); assert_eq!(not_max.get_version(), Some(Version::Random)); - assert_eq!(max, Builder::from_bytes([0xff; 16]).with_version(Version::Max).into_uuid()); + assert_eq!( + max, + Builder::from_bytes([0xff; 16]) + .with_version(Version::Max) + .into_uuid() + ); } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_predefined_namespaces() { assert_eq!( Uuid::NAMESPACE_DNS.hyphenated().to_string(), @@ -1150,7 +1229,14 @@ mod tests { #[cfg(feature = "v3")] #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_get_version_v3() { let uuid = Uuid::new_v3(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); @@ -1159,7 +1245,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_get_variant() { let uuid1 = new(); let uuid2 = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap(); @@ -1177,7 +1270,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_to_simple_string() { let uuid1 = new(); let s = uuid1.simple().to_string(); @@ -1187,7 +1287,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_hyphenated_string() { let uuid1 = new(); let s = uuid1.hyphenated().to_string(); @@ -1197,7 +1304,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_upper_lower_hex() { use std::fmt::Write; @@ -1219,8 +1333,12 @@ mod tests { check!(buf, "{:X}", u, 36, |c| c.is_uppercase() || c.is_digit(10) || c == '-'); - check!(buf, "{:#x}", u, 36, |c| c.is_lowercase() || c.is_digit(10) || c == '-'); - check!(buf, "{:#X}", u, 36, |c| c.is_uppercase() || c.is_digit(10) || c == '-'); + check!(buf, "{:#x}", u, 36, |c| c.is_lowercase() + || c.is_digit(10) + || c == '-'); + check!(buf, "{:#X}", u, 36, |c| c.is_uppercase() + || c.is_digit(10) + || c == '-'); check!(buf, "{:X}", u.hyphenated(), 36, |c| c.is_uppercase() || c.is_digit(10) @@ -1246,7 +1364,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_to_urn_string() { let uuid1 = new(); let ss = uuid1.urn().to_string(); @@ -1258,7 +1383,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_to_simple_string_matching() { let uuid1 = new(); @@ -1271,7 +1403,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_string_roundtrip() { let uuid = new(); @@ -1285,7 +1424,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_fields() { let d1: u32 = 0xa1a2a3a4; let d2: u16 = 0xb1b2; @@ -1300,7 +1446,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_fields_le() { let d1: u32 = 0xa4a3a2a1; let d2: u16 = 0xb2b1; @@ -1315,7 +1468,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_as_fields() { let u = new(); let (d1, d2, d3, d4) = u.as_fields(); @@ -1328,7 +1488,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_fields_roundtrip() { let d1_in: u32 = 0xa1a2a3a4; let d2_in: u16 = 0xb1b2; @@ -1345,7 +1512,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_fields_le_roundtrip() { let d1_in: u32 = 0xa4a3a2a1; let d2_in: u16 = 0xb2b1; @@ -1362,7 +1536,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_fields_le_are_actually_le() { let d1_in: u32 = 0xa1a2a3a4; let d2_in: u16 = 0xb1b2; @@ -1379,7 +1560,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_u128() { let v_in: u128 = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8; @@ -1391,7 +1579,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_u128_le() { let v_in: u128 = 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1; @@ -1403,7 +1598,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_u64_pair() { let high_in: u64 = 0xa1a2a3a4b1b2c1c2; let low_in: u64 = 0xd1d2d3d4d5d6d7d8; @@ -1416,7 +1618,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_u128_roundtrip() { let v_in: u128 = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8; @@ -1427,7 +1636,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_u128_le_roundtrip() { let v_in: u128 = 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1; @@ -1438,7 +1654,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_u64_pair_roundtrip() { let high_in: u64 = 0xa1a2a3a4b1b2c1c2; let low_in: u64 = 0xd1d2d3d4d5d6d7d8; @@ -1451,7 +1674,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_u128_le_is_actually_le() { let v_in: u128 = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8; @@ -1462,7 +1692,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_slice() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, @@ -1476,7 +1713,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_from_bytes() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, @@ -1490,7 +1734,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_as_bytes() { let u = new(); let ub = u.as_bytes(); @@ -1503,7 +1754,39 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg(feature = "std")] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] + fn test_convert_vec() { + use crate::std::{convert::TryInto, vec::Vec}; + + let u = new(); + let ub = u.as_ref(); + + let v: Vec = u.into(); + + assert_eq!(&v, ub); + + let uv: Uuid = v.try_into().unwrap(); + + assert_eq!(uv, u); + } + + #[test] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_bytes_roundtrip() { let b_in: crate::Bytes = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, @@ -1518,7 +1801,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_bytes_le_roundtrip() { let b = [ 0xa1, 0xa2, 0xa3, 0xa4, 0xb1, 0xb2, 0xc1, 0xc2, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, @@ -1535,7 +1825,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_iterbytes_impl_for_uuid() { let mut set = std::collections::HashSet::new(); let id1 = new(); diff --git a/src/macros.rs b/src/macros.rs index 281c533..eb95725 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -15,15 +15,8 @@ macro_rules! define_uuid_macro { macro_rules! uuid { ($uuid:literal) => {{ const OUTPUT: $crate::Uuid = match $crate::Uuid::try_parse($uuid) { - Ok(u) => u, - Err(_) => { - // here triggers const_err - // const_panic requires 1.57 - #[allow(unconditional_panic)] - let _ = ["invalid uuid representation"][1]; - - loop {} // -> never type - } + $crate::__macro_support::Ok(u) => u, + $crate::__macro_support::Err(_) => panic!("invalid UUID"), }; OUTPUT }}; diff --git a/src/md5.rs b/src/md5.rs index fce5d9b..a746f22 100644 --- a/src/md5.rs +++ b/src/md5.rs @@ -1,6 +1,6 @@ #[cfg(feature = "v3")] pub(crate) fn hash(ns: &[u8], src: &[u8]) -> [u8; 16] { - use md_5::{Digest, Md5}; + use md5::{Digest, Md5}; let mut hasher = Md5::new(); diff --git a/src/parser.rs b/src/parser.rs index bc5f826..0eabcfe 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -472,6 +472,14 @@ mod tests { index: 20, })) ); + + assert_eq!( + Uuid::parse_str("\u{bcf3c}"), + Err(Error(ErrorKind::Char { + character: '\u{bcf3c}', + index: 1 + })) + ); } #[test] diff --git a/src/timestamp.rs b/src/timestamp.rs index 2f95ac4..27112d1 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -72,6 +72,11 @@ impl Timestamp { /// Construct a `Timestamp` from an RFC4122 timestamp and counter, as used /// in versions 1 and 6 UUIDs. + /// + /// # Overflow + /// + /// If conversion from RFC4122 ticks to the internal timestamp format would overflow + /// it will wrap. pub const fn from_rfc4122(ticks: u64, counter: u16) -> Self { #[cfg(not(any(feature = "v1", feature = "v6")))] { @@ -89,6 +94,11 @@ impl Timestamp { } /// Construct a `Timestamp` from a Unix timestamp, as used in version 7 UUIDs. + /// + /// # Overflow + /// + /// If conversion from RFC4122 ticks to the internal timestamp format would overflow + /// it will wrap. pub fn from_unix(context: impl ClockSequence, seconds: u64, nanos: u32) -> Self { #[cfg(not(any(feature = "v1", feature = "v6")))] { @@ -110,6 +120,11 @@ impl Timestamp { /// Get the value of the timestamp as an RFC4122 timestamp and counter, /// as used in versions 1 and 6 UUIDs. + /// + /// # Overflow + /// + /// If conversion from RFC4122 ticks to the internal timestamp format would overflow + /// it will wrap. #[cfg(any(feature = "v1", feature = "v6"))] pub const fn to_rfc4122(&self) -> (u64, u16) { ( @@ -119,38 +134,37 @@ impl Timestamp { } /// Get the value of the timestamp as a Unix timestamp, as used in version 7 UUIDs. + /// + /// # Overflow + /// + /// If conversion from RFC4122 ticks to the internal timestamp format would overflow + /// it will wrap. pub const fn to_unix(&self) -> (u64, u32) { (self.seconds, self.nanos) } #[cfg(any(feature = "v1", feature = "v6"))] const fn unix_to_rfc4122_ticks(seconds: u64, nanos: u32) -> u64 { - let ticks = UUID_TICKS_BETWEEN_EPOCHS + seconds * 10_000_000 + nanos as u64 / 100; - - ticks + UUID_TICKS_BETWEEN_EPOCHS + .wrapping_add(seconds.wrapping_mul(10_000_000)) + .wrapping_add(nanos as u64 / 100) } const fn rfc4122_to_unix(ticks: u64) -> (u64, u32) { ( - (ticks - UUID_TICKS_BETWEEN_EPOCHS) / 10_000_000, - ((ticks - UUID_TICKS_BETWEEN_EPOCHS) % 10_000_000) as u32 * 100, + ticks.wrapping_sub(UUID_TICKS_BETWEEN_EPOCHS) / 10_000_000, + (ticks.wrapping_sub(UUID_TICKS_BETWEEN_EPOCHS) % 10_000_000) as u32 * 100, ) } - #[deprecated(note = "use `to_unix` instead")] + #[deprecated(note = "use `to_unix` instead; this method will be removed in a future release")] /// Get the number of fractional nanoseconds in the Unix timestamp. /// /// This method is deprecated and probably doesn't do what you're expecting it to. /// It doesn't return the timestamp as nanoseconds since the Unix epoch, it returns /// the fractional seconds of the timestamp. pub const fn to_unix_nanos(&self) -> u32 { - // NOTE: This method never did what it said on the tin: instead of - // converting the timestamp into nanos it simply returned the nanoseconds - // part of the timestamp. - // - // We can't fix the behavior because the return type is too small to fit - // a useful value for nanoseconds since the epoch. - self.nanos + panic!("`Timestamp::to_unix_nanos` is deprecated and will be removed: use `Timestamp::to_unix` instead") } } @@ -190,7 +204,6 @@ pub(crate) const fn decode_rfc4122_timestamp(uuid: &Uuid) -> (u64, u16) { (ticks, counter) } -#[cfg(uuid_unstable)] pub(crate) const fn encode_sorted_rfc4122_timestamp( ticks: u64, counter: u16, @@ -214,7 +227,6 @@ pub(crate) const fn encode_sorted_rfc4122_timestamp( Uuid::from_fields(time_high, time_mid, time_low_and_version, &d4) } -#[cfg(uuid_unstable)] pub(crate) const fn decode_sorted_rfc4122_timestamp(uuid: &Uuid) -> (u64, u16) { let bytes = uuid.as_bytes(); @@ -232,13 +244,12 @@ pub(crate) const fn decode_sorted_rfc4122_timestamp(uuid: &Uuid) -> (u64, u16) { (ticks, counter) } -#[cfg(uuid_unstable)] pub(crate) const fn encode_unix_timestamp_millis(millis: u64, random_bytes: &[u8; 10]) -> Uuid { let millis_high = ((millis >> 16) & 0xFFFF_FFFF) as u32; let millis_low = (millis & 0xFFFF) as u16; let random_and_version = - (random_bytes[0] as u16 | ((random_bytes[1] as u16) << 8) & 0x0FFF) | (0x7 << 12); + (random_bytes[1] as u16 | ((random_bytes[0] as u16) << 8) & 0x0FFF) | (0x7 << 12); let mut d4 = [0; 8]; @@ -254,7 +265,6 @@ pub(crate) const fn encode_unix_timestamp_millis(millis: u64, random_bytes: &[u8 Uuid::from_fields(millis_high, millis_low, random_and_version, &d4) } -#[cfg(uuid_unstable)] pub(crate) const fn decode_unix_timestamp_millis(uuid: &Uuid) -> u64 { let bytes = uuid.as_bytes(); @@ -268,29 +278,48 @@ pub(crate) const fn decode_unix_timestamp_millis(uuid: &Uuid) -> u64 { millis } -#[cfg(all(feature = "std", feature = "js", target_arch = "wasm32"))] +#[cfg(all( + feature = "std", + feature = "js", + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ) +))] fn now() -> (u64, u32) { use wasm_bindgen::prelude::*; #[wasm_bindgen] extern "C" { - #[wasm_bindgen(js_namespace = Date)] - fn now() -> f64; + // NOTE: This signature works around https://bugzilla.mozilla.org/show_bug.cgi?id=1787770 + #[wasm_bindgen(js_namespace = Date, catch)] + fn now() -> Result; } - let now = now(); + let now = now().unwrap_throw(); let secs = (now / 1_000.0) as u64; let nanos = ((now % 1_000.0) * 1_000_000.0) as u32; - dbg!((secs, nanos)) + (secs, nanos) } -#[cfg(all(feature = "std", any(not(feature = "js"), not(target_arch = "wasm32"))))] +#[cfg(all( + feature = "std", + any( + not(feature = "js"), + not(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + )) + ) +))] fn now() -> (u64, u32) { - let dur = std::time::SystemTime::UNIX_EPOCH - .elapsed() - .expect("Getting elapsed time since UNIX_EPOCH. If this fails, we've somehow violated causality"); + let dur = std::time::SystemTime::UNIX_EPOCH.elapsed().expect( + "Getting elapsed time since UNIX_EPOCH. If this fails, we've somehow violated causality", + ); (dur.as_secs(), dur.subsec_nanos()) } @@ -403,7 +432,37 @@ pub mod context { // increment the clock sequence we want to wrap once it becomes larger // than what we can represent in a "u14". Otherwise there'd be patches // where the clock sequence doesn't change regardless of the timestamp - self.count.fetch_add(1, Ordering::AcqRel) % (u16::MAX >> 2) + self.count.fetch_add(1, Ordering::AcqRel) & (u16::MAX >> 2) } } } + +#[cfg(all(test, any(feature = "v1", feature = "v6")))] +mod tests { + use super::*; + + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] + use wasm_bindgen_test::*; + + #[test] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] + fn rfc4122_unix_does_not_panic() { + // Ensure timestamp conversions never panic + Timestamp::unix_to_rfc4122_ticks(u64::MAX, 0); + Timestamp::unix_to_rfc4122_ticks(0, u32::MAX); + Timestamp::unix_to_rfc4122_ticks(u64::MAX, u32::MAX); + + Timestamp::rfc4122_to_unix(u64::MAX); + } +} diff --git a/src/v1.rs b/src/v1.rs index e19c8a3..41febab 100644 --- a/src/v1.rs +++ b/src/v1.rs @@ -100,11 +100,22 @@ mod tests { use super::*; use crate::{std::string::ToString, Variant, Version}; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { let time: u64 = 1_496_854_535; let time_fraction: u32 = 812_946_000; @@ -134,7 +145,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] #[cfg(all(feature = "std", feature = "rng"))] fn test_now() { let node = [1, 2, 3, 4, 5, 6]; @@ -146,14 +164,21 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new_context() { let time: u64 = 1_496_854_535; let time_fraction: u32 = 812_946_000; let node = [1, 2, 3, 4, 5, 6]; // This context will wrap - let context = Context::new((u16::MAX >> 2) - 1); + let context = Context::new(u16::MAX >> 2); let uuid1 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); @@ -161,7 +186,7 @@ mod tests { let uuid2 = Uuid::new_v1(Timestamp::from_unix(&context, time, time_fraction), &node); - assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382); + assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383); assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0); let time = 1_496_854_535; diff --git a/src/v3.rs b/src/v3.rs index cc7cb9a..ed356d4 100644 --- a/src/v3.rs +++ b/src/v3.rs @@ -42,7 +42,11 @@ impl Uuid { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; use crate::{std::string::ToString, Variant, Version}; @@ -131,7 +135,14 @@ mod tests { ]; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { for &(ref ns, ref name, _) in FIXTURE { let uuid = Uuid::new_v3(*ns, name.as_bytes()); @@ -141,7 +152,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_hyphenated_string() { for &(ref ns, ref name, ref expected) in FIXTURE { let uuid = Uuid::new_v3(*ns, name.as_bytes()); diff --git a/src/v4.rs b/src/v4.rs index e78fb1e..3c42473 100644 --- a/src/v4.rs +++ b/src/v4.rs @@ -40,11 +40,22 @@ mod tests { use super::*; use crate::{Variant, Version}; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { let uuid = Uuid::new_v4(); @@ -53,7 +64,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_get_version() { let uuid = Uuid::new_v4(); diff --git a/src/v5.rs b/src/v5.rs index c3dd447..265aa1a 100644 --- a/src/v5.rs +++ b/src/v5.rs @@ -41,7 +41,11 @@ impl Uuid { mod tests { use super::*; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; use crate::{std::string::ToString, Variant, Version}; @@ -130,7 +134,14 @@ mod tests { ]; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_get_version() { let uuid = Uuid::new_v5(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); @@ -139,7 +150,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_hyphenated() { for &(ref ns, ref name, ref expected) in FIXTURE { let uuid = Uuid::new_v5(*ns, name.as_bytes()); @@ -149,7 +167,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { for &(ref ns, ref name, ref u) in FIXTURE { let uuid = Uuid::new_v5(*ns, name.as_bytes()); diff --git a/src/v6.rs b/src/v6.rs index 07644fd..09c156f 100644 --- a/src/v6.rs +++ b/src/v6.rs @@ -86,9 +86,9 @@ impl Uuid { /// /// * [Version 6 UUIDs in Draft RFC: New UUID Formats, Version 4](https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04#section-5.1) /// - /// [`Timestamp`]: v1/struct.Timestamp.html - /// [`ClockSequence`]: v1/trait.ClockSequence.html - /// [`Context`]: v1/struct.Context.html + /// [`Timestamp`]: timestamp/struct.Timestamp.html + /// [`ClockSequence`]: timestamp/trait.ClockSequence.html + /// [`Context`]: timestamp/context/struct.Context.html pub fn new_v6(ts: Timestamp, node_id: &[u8; 6]) -> Self { let (ticks, counter) = ts.to_rfc4122(); @@ -102,11 +102,22 @@ mod tests { use crate::{Context, Variant, Version}; use std::string::ToString; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { let time: u64 = 1_496_854_535; let time_fraction: u32 = 812_946_000; @@ -136,7 +147,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] #[cfg(all(feature = "std", feature = "rng"))] fn test_now() { let node = [1, 2, 3, 4, 5, 6]; @@ -148,14 +166,21 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new_context() { let time: u64 = 1_496_854_535; let time_fraction: u32 = 812_946_000; let node = [1, 2, 3, 4, 5, 6]; // This context will wrap - let context = Context::new((u16::MAX >> 2) - 1); + let context = Context::new(u16::MAX >> 2); let uuid1 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node); @@ -163,7 +188,7 @@ mod tests { let uuid2 = Uuid::new_v6(Timestamp::from_unix(&context, time, time_fraction), &node); - assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16382); + assert_eq!(uuid1.get_timestamp().unwrap().to_rfc4122().1, 16383); assert_eq!(uuid2.get_timestamp().unwrap().to_rfc4122().1, 0); let time = 1_496_854_535; diff --git a/src/v7.rs b/src/v7.rs index 4497ea3..ea8f474 100644 --- a/src/v7.rs +++ b/src/v7.rs @@ -3,7 +3,7 @@ //! Note that you need to enable the `v7` Cargo feature //! in order to use this module. -use crate::{std::convert::TryInto, rng, timestamp::Timestamp, Builder, Uuid}; +use crate::{rng, std::convert::TryInto, timestamp::Timestamp, Builder, Uuid}; impl Uuid { /// Create a new version 7 UUID using the current time value and random bytes. @@ -57,11 +57,22 @@ impl Uuid { mod tests { use super::*; use crate::{std::string::ToString, NoContext, Variant, Version}; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { let ts: u64 = 1645557742000; @@ -82,7 +93,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] #[cfg(feature = "std")] fn test_now() { let uuid = Uuid::now_v7(); @@ -92,7 +110,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_sorting() { let time1: u64 = 1_496_854_535; let time_fraction1: u32 = 812_000_000; @@ -108,7 +133,14 @@ mod tests { } #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new_timestamp_roundtrip() { let time: u64 = 1_496_854_535; let time_fraction: u32 = 812_000_000; diff --git a/src/v8.rs b/src/v8.rs index a54a979..b853ac7 100644 --- a/src/v8.rs +++ b/src/v8.rs @@ -36,11 +36,22 @@ mod tests { use crate::{Variant, Version}; use std::string::ToString; - #[cfg(target_arch = "wasm32")] + #[cfg(all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ))] use wasm_bindgen_test::*; #[test] - #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] + #[cfg_attr( + all( + target_arch = "wasm32", + target_vendor = "unknown", + target_os = "unknown" + ), + wasm_bindgen_test + )] fn test_new() { let buf: [u8; 16] = [ 0xf, 0xe, 0xd, 0xc, 0xb, 0xa, 0x9, 0x8, 0x7, 0x6, 0x5, 0x4, 0x3, 0x2, 0x1, 0x0, diff --git a/tests/macros.rs b/tests/macros.rs deleted file mode 100644 index c7cf2a4..0000000 --- a/tests/macros.rs +++ /dev/null @@ -1,11 +0,0 @@ -#[cfg(feature = "macro-diagnostics")] -#[test] -fn ui() { - let t = trybuild::TestCases::new(); - - t.pass("tests/ui/compile_pass/*.rs"); - - if rustversion::cfg!(nightly) { - t.compile_fail("tests/ui/compile_fail/*.rs"); - } -} diff --git a/tests/ui/compile_fail/invalid_parse.rs b/tests/ui/compile_fail/invalid_parse.rs deleted file mode 100644 index f67456b..0000000 --- a/tests/ui/compile_fail/invalid_parse.rs +++ /dev/null @@ -1,45 +0,0 @@ -use uuid::{uuid, Uuid}; - -const _: Uuid = uuid!(""); -const _: Uuid = uuid!("!"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E45"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faaXB6BFF329BF39FA1E4"); -const _: Uuid = uuid!("F9168C5E-CEB-24fa-eB6BFF32-BF39FA1E4"); -const _: Uuid = uuid!("01020304-1112-2122-3132-41424344"); -const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c88"); -const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0cg8"); -const _: Uuid = uuid!("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8"); - -// Test error reporting -const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c"); -const _: Uuid = uuid!("67e550X410b1426f9247bb680e5fe0cd"); -const _: Uuid = uuid!("67e550-4105b1426f9247bb680e5fe0c"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BF1-02BF39FA1E4"); - - -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); -const _: Uuid = uuid!("01020304-1112-2122-3132-41424344"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); -const _: Uuid = uuid!("urn:uuid:F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); -const _: Uuid = uuid!("urn:uuid:F9168C5E-CEB2-4faa-B2cBF-32BF39FA1E4"); -const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-B0a75-32BF39FA1E4}"); - -const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-B6BF-329Bz39FA1E4}"); - -// group 0 has invalid length -const _: Uuid = uuid!("67e550-4105b1426f9247bb680e5fe0c"); - -const _: Uuid = uuid!("504410岡林aab1426f9247bb680e5fe0c8"); -const _: Uuid = uuid!("504410😎👍aab1426f9247bb680e5fe0c8"); - -const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-👍5-32BF39FA1E4}"); - -const _: Uuid = uuid!("F916"); -const _: Uuid = uuid!("F916x"); - -fn main() {} diff --git a/tests/ui/compile_fail/invalid_parse.stderr b/tests/ui/compile_fail/invalid_parse.stderr deleted file mode 100644 index b630494..0000000 --- a/tests/ui/compile_fail/invalid_parse.stderr +++ /dev/null @@ -1,197 +0,0 @@ -error: invalid length: expected length 32 for simple format, found 0 - --> tests/ui/compile_fail/invalid_parse.rs:3:17 - | -3 | const _: Uuid = uuid!(""); - | ^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `!` at 1 - --> tests/ui/compile_fail/invalid_parse.rs:4:24 - | -4 | const _: Uuid = uuid!("!"); - | ^ - -error: invalid group length in group 4: expected 12, found 13 - --> tests/ui/compile_fail/invalid_parse.rs:5:48 - | -5 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E45"); - | ^^^^^^^^^^^^^ - -error: invalid group length in group 3: expected 4, found 3 - --> tests/ui/compile_fail/invalid_parse.rs:6:43 - | -6 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); - | ^^^ - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `G` at 21 - --> tests/ui/compile_fail/invalid_parse.rs:7:44 - | -7 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); - | ^ - -error: invalid group count: expected 5, found 4 - --> tests/ui/compile_fail/invalid_parse.rs:8:17 - | -8 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid group count: expected 5, found 3 - --> tests/ui/compile_fail/invalid_parse.rs:9:17 - | -9 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `X` at 19 - --> tests/ui/compile_fail/invalid_parse.rs:10:42 - | -10 | const _: Uuid = uuid!("F9168C5E-CEB2-4faaXB6BFF329BF39FA1E4"); - | ^ - -error: invalid group length in group 1: expected 4, found 3 - --> tests/ui/compile_fail/invalid_parse.rs:11:33 - | -11 | const _: Uuid = uuid!("F9168C5E-CEB-24fa-eB6BFF32-BF39FA1E4"); - | ^^^ - -error: invalid group length in group 4: expected 12, found 8 - --> tests/ui/compile_fail/invalid_parse.rs:12:48 - | -12 | const _: Uuid = uuid!("01020304-1112-2122-3132-41424344"); - | ^^^^^^^^ - -error: invalid length: expected length 32 for simple format, found 33 - --> tests/ui/compile_fail/invalid_parse.rs:13:17 - | -13 | const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c88"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `g` at 32 - --> tests/ui/compile_fail/invalid_parse.rs:14:55 - | -14 | const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0cg8"); - | ^ - -error: invalid length: expected length 32 for simple format, found 31 - --> tests/ui/compile_fail/invalid_parse.rs:18:17 - | -18 | const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `X` at 7 - --> tests/ui/compile_fail/invalid_parse.rs:19:30 - | -19 | const _: Uuid = uuid!("67e550X410b1426f9247bb680e5fe0cd"); - | ^ - -error: invalid group count: expected 5, found 2 - --> tests/ui/compile_fail/invalid_parse.rs:20:17 - | -20 | const _: Uuid = uuid!("67e550-4105b1426f9247bb680e5fe0c"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid group length in group 3: expected 4, found 5 - --> tests/ui/compile_fail/invalid_parse.rs:21:43 - | -21 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BF1-02BF39FA1E4"); - | ^^^^^ - -error: invalid group length in group 3: expected 4, found 3 - --> tests/ui/compile_fail/invalid_parse.rs:24:43 - | -24 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BBF-329BF39FA1E4"); - | ^^^ - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `G` at 21 - --> tests/ui/compile_fail/invalid_parse.rs:25:44 - | -25 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); - | ^ - -error: invalid group length in group 4: expected 12, found 8 - --> tests/ui/compile_fail/invalid_parse.rs:26:48 - | -26 | const _: Uuid = uuid!("01020304-1112-2122-3132-41424344"); - | ^^^^^^^^ - -error: invalid group count: expected 5, found 4 - --> tests/ui/compile_fail/invalid_parse.rs:27:17 - | -27 | const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BFF329BF39FA1E4"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `G` at 30 - --> tests/ui/compile_fail/invalid_parse.rs:28:53 - | -28 | const _: Uuid = uuid!("urn:uuid:F9168C5E-CEB2-4faa-BGBF-329BF39FA1E4"); - | ^ - -error: invalid group length in group 3: expected 4, found 5 - --> tests/ui/compile_fail/invalid_parse.rs:29:52 - | -29 | const _: Uuid = uuid!("urn:uuid:F9168C5E-CEB2-4faa-B2cBF-32BF39FA1E4"); - | ^^^^^ - -error: invalid group length in group 3: expected 4, found 5 - --> tests/ui/compile_fail/invalid_parse.rs:30:44 - | -30 | const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-B0a75-32BF39FA1E4}"); - | ^^^^^ - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `z` at 30 - --> tests/ui/compile_fail/invalid_parse.rs:32:53 - | -32 | const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-B6BF-329Bz39FA1E4}"); - | ^ - -error: invalid group count: expected 5, found 2 - --> tests/ui/compile_fail/invalid_parse.rs:35:17 - | -35 | const _: Uuid = uuid!("67e550-4105b1426f9247bb680e5fe0c"); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `岡` at 7 - --> tests/ui/compile_fail/invalid_parse.rs:37:30 - | -37 | const _: Uuid = uuid!("504410岡林aab1426f9247bb680e5fe0c8"); - | ^^ - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `😎` at 7 - --> tests/ui/compile_fail/invalid_parse.rs:38:30 - | -38 | const _: Uuid = uuid!("504410😎👍aab1426f9247bb680e5fe0c8"); - | ^^ - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `👍` at 21 - --> tests/ui/compile_fail/invalid_parse.rs:40:44 - | -40 | const _: Uuid = uuid!("{F9168C5E-CEB2-4faa-👍5-32BF39FA1E4}"); - | ^^ - -error: invalid length: expected length 32 for simple format, found 4 - --> tests/ui/compile_fail/invalid_parse.rs:42:17 - | -42 | const _: Uuid = uuid!("F916"); - | ^^^^^^^^^^^^^ - | - = note: this error originates in the macro `uuid` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: invalid character: expected an optional prefix of `urn:uuid:` followed by [0-9a-zA-Z], found `x` at 5 - --> tests/ui/compile_fail/invalid_parse.rs:43:28 - | -43 | const _: Uuid = uuid!("F916x"); - | ^ diff --git a/tests/ui/compile_pass/renamed.rs b/tests/ui/compile_pass/renamed.rs deleted file mode 100644 index 321172e..0000000 --- a/tests/ui/compile_pass/renamed.rs +++ /dev/null @@ -1,11 +0,0 @@ -use ::uuid::{uuid as id, Uuid as Id}; - -mod uuid { - struct MyType; -} - -struct Uuid; - -const _: Id = id!("67e55044-10b1-426f-9247-bb680e5fe0c8"); - -fn main() {} diff --git a/tests/ui/compile_pass/valid.rs b/tests/ui/compile_pass/valid.rs deleted file mode 100644 index 1f536dc..0000000 --- a/tests/ui/compile_pass/valid.rs +++ /dev/null @@ -1,20 +0,0 @@ -use uuid::{uuid, Uuid}; - -const _: Uuid = uuid!("00000000000000000000000000000000"); -const _: Uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"); -const _: Uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"); -const _: Uuid = uuid!("F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4"); -const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c8"); -const _: Uuid = uuid!("01020304-1112-2122-3132-414243444546"); -const _: Uuid = uuid!("urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8"); - -// Nil -const _: Uuid = uuid!("00000000000000000000000000000000"); -const _: Uuid = uuid!("00000000-0000-0000-0000-000000000000"); - -// valid hyphenated -const _: Uuid = uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"); -// valid short -const _: Uuid = uuid!("67e5504410b1426f9247bb680e5fe0c8"); - -fn main() {} -- cgit v1.2.3