guid-create-0.5.2/Cargo.lock0000644000000350720000000000100112130ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "aho-corasick" version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] name = "anstyle" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "bitflags" version = "2.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" [[package]] name = "bytemuck" version = "1.23.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3995eaeebcdf32f91f980d360f78732ddc061097ab4e39991ae7a6ace9194677" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4f154e572231cb6ba2bd1176980827e3d5dc04cc183a75dea38109fbdd672d29" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "cfg-if" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clap" version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" dependencies = [ "anstyle", "clap_lex", "terminal_size", ] [[package]] name = "clap_lex" version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "condtype" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" [[package]] name = "divan" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a405457ec78b8fe08b0e32b4a3570ab5dff6dd16eb9e76a5ee0a9d9cbd898933" dependencies = [ "cfg-if", "clap", "condtype", "divan-macros", "libc", "regex-lite", ] [[package]] name = "divan-macros" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9556bc800956545d6420a640173e5ba7dfa82f38d3ea5a167eb555bc69ac3323" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "env_logger" version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19187fea3ac7e84da7dacf48de0c45d63c6a76f9490dae389aead16c243fce3" dependencies = [ "log", "regex", ] [[package]] name = "errno" version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", "windows-sys 0.61.0", ] [[package]] name = "getrandom" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" dependencies = [ "cfg-if", "libc", "wasi 0.11.1+wasi-snapshot-preview1", ] [[package]] name = "getrandom" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", "r-efi", "wasi 0.14.7+wasi-0.2.4", ] [[package]] name = "guid-create" version = "0.5.2" dependencies = [ "bytemuck", "divan", "quickcheck", "quickcheck_macros", "rand 0.9.2", "serde", "winapi", ] [[package]] name = "libc" version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "linux-raw-sys" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "log" version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "memchr" version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "ppv-lite86" version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ "zerocopy", ] [[package]] name = "proc-macro2" version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quickcheck" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "588f6378e4dd99458b60ec275b4477add41ce4fa9f64dcba6f15adccb19b50d6" dependencies = [ "env_logger", "log", "rand 0.8.5", ] [[package]] name = "quickcheck_macros" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f71ee38b42f8459a88d3362be6f9b841ad2d5421844f61eb1c59c11bff3ac14a" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "quote" version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] [[package]] name = "r-efi" version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "rand_core 0.6.4", ] [[package]] name = "rand" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" dependencies = [ "rand_chacha", "rand_core 0.9.3", ] [[package]] name = "rand_chacha" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", "rand_core 0.9.3", ] [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom 0.2.16", ] [[package]] name = "rand_core" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ "getrandom 0.3.3", ] [[package]] name = "regex" version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" dependencies = [ "aho-corasick", "memchr", "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] [[package]] name = "regex-lite" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "943f41321c63ef1c92fd763bfe054d2668f7f225a5c29f0105903dc2fc04ba30" [[package]] name = "regex-syntax" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "caf4aa5b0f434c91fe5c7f1ecb6a5ece2130b02ad2a590589dda5146df959001" [[package]] name = "rustix" version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys 0.61.0", ] [[package]] name = "serde" version = "1.0.226" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0dca6411025b24b60bfa7ec1fe1f8e710ac09782dca409ee8237ba74b51295fd" dependencies = [ "serde_core", ] [[package]] name = "serde_core" version = "1.0.226" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ba2ba63999edb9dac981fb34b3e5c0d111a69b0924e253ed29d83f7c99e966a4" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.226" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8db53ae22f34573731bafa1db20f04027b2d25e02d8205921b569171699cdb33" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "syn" version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "terminal_size" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" dependencies = [ "rustix", "windows-sys 0.60.2", ] [[package]] name = "unicode-ident" version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] name = "wasi" version = "0.14.7+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" dependencies = [ "wasip2", ] [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ "wit-bindgen", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-link" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" [[package]] name = "windows-link" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ "windows-targets", ] [[package]] name = "windows-sys" version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa" dependencies = [ "windows-link 0.2.0", ] [[package]] name = "windows-targets" version = "0.53.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" dependencies = [ "windows-link 0.1.3", "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" [[package]] name = "windows_aarch64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" [[package]] name = "windows_i686_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" [[package]] name = "windows_i686_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" [[package]] name = "windows_i686_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" [[package]] name = "windows_x86_64_gnu" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" [[package]] name = "windows_x86_64_gnullvm" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" [[package]] name = "windows_x86_64_msvc" version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "wit-bindgen" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "zerocopy" version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" version = "0.8.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" dependencies = [ "proc-macro2", "quote", "syn", ] guid-create-0.5.2/Cargo.toml0000644000000030210000000000100112230ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.60.0" name = "guid-create" version = "0.5.2" authors = ["kurt "] build = false autolib = false autobins = false autoexamples = false autotests = false autobenches = false description = "Rust helper for creating GUIDs" readme = "README.md" keywords = ["guid"] license = "MIT" repository = "https://github.com/kurtlawrence/guid-create" [package.metadata."docs.rs"] all-features = true [features] bytemuck = ["dep:bytemuck"] default = [ "std", "rand", ] rand = ["dep:rand"] serde = ["dep:serde"] std = [] [lib] name = "guid_create" path = "src/lib.rs" [[bench]] name = "bench" path = "benches/bench.rs" harness = false [dependencies.bytemuck] version = "1" features = ["derive"] optional = true [dependencies.rand] version = "0.9" optional = true [dependencies.serde] version = "1" optional = true [dev-dependencies.divan] version = "0.1.21" [dev-dependencies.quickcheck] version = "1" [dev-dependencies.quickcheck_macros] version = "1" [target."cfg(windows)".dependencies.winapi] version = "0.3.9" guid-create-0.5.2/Cargo.toml.orig0000644000000014540000000000100121720ustar [package] name = "guid-create" version = "0.5.2" authors = ["kurt "] description = "Rust helper for creating GUIDs" repository = "https://github.com/kurtlawrence/guid-create" readme = "README.md" keywords = ["guid"] license = "MIT" edition = "2021" rust-version="1.60.0" [dependencies] rand = { version = "0.9", optional = true } serde = { version = "1", optional = true } bytemuck = { version = "1", optional = true, features = [ "derive" ]} [features] default = ["std", "rand"] std = [] rand = ["dep:rand"] serde = ["dep:serde"] bytemuck = ["dep:bytemuck"] [target.'cfg(windows)'.dependencies] winapi = "0.3.9" [dev-dependencies] quickcheck = "1" quickcheck_macros = "1" divan = "0.1.21" [[bench]] name = "bench" harness = false [package.metadata."docs.rs"] all-features = true guid-create-0.5.2/Cargo.toml.orig000064400000000000000000000014541046102023000147140ustar 00000000000000[package] name = "guid-create" version = "0.5.2" authors = ["kurt "] description = "Rust helper for creating GUIDs" repository = "https://github.com/kurtlawrence/guid-create" readme = "README.md" keywords = ["guid"] license = "MIT" edition = "2021" rust-version="1.60.0" [dependencies] rand = { version = "0.9", optional = true } serde = { version = "1", optional = true } bytemuck = { version = "1", optional = true, features = [ "derive" ]} [features] default = ["std", "rand"] std = [] rand = ["dep:rand"] serde = ["dep:serde"] bytemuck = ["dep:bytemuck"] [target.'cfg(windows)'.dependencies] winapi = "0.3.9" [dev-dependencies] quickcheck = "1" quickcheck_macros = "1" divan = "0.1.21" [[bench]] name = "bench" harness = false [package.metadata."docs.rs"] all-features = true guid-create-0.5.2/LICENSE000064400000000000000000000020551046102023000130300ustar 00000000000000MIT License Copyright (c) 2018 kurtlawrence Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. guid-create-0.5.2/README.md000064400000000000000000000011741046102023000133030ustar 00000000000000# guid-create Rust helper for randomly creating GUIDs. ``` rust extern crate guid_create; use guid_create::GUID; // Create GUIDs let guid = GUID::rand(); let guid = GUID::parse("87935CDE-7094-4C2B-A0F4-DD7D512DD261").unwrap(); let guid = GUID::build_from_components(0x87935CDE, 0x7094, 0x4C2B, &[0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61], ); let guid = GUID::build_from_slice(&[ 0x87, 0x93, 0x5C, 0xDE, 0x70, 0x94, 0x4C, 0x2B, 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61,]); // View GUIDs guid.to_string(); // 87935CDE-7094-4C2B-A0F4-DD7D512DD261 // Check GUIDs guid.data1(); guid.data2(); guid.data3(); guid.data4(); ```guid-create-0.5.2/pass_build_push.sh000064400000000000000000000015261046102023000155450ustar 00000000000000#!/bin/sh upload_files() { echo "Travis branch: " $TRAVIS_BRANCH "..." if [ $TRAVIS_BRANCH == "auto" ]; then echo "Will merge to master..." git clone https://${GH_TOKEN}@github.com/kurtlawrence/guid-create.git cd guid-create/ git remote -v git branch -a git merge origin/auto if [[ $? != 0 ]]; then echo "Merge failed..." exit 1 else echo "Merge succeeded..." git commit --amend -m "Passed travis build: $TRAVIS_BUILD_NUMBER" cargo login $CARGO_LOGIN cargo publish if [[ $? != 0 ]]; then echo "Publish failed..." exit 1 else echo "Publish succeeded..." git push if [[ $? != 0 ]]; then echo "Push to origin failed..." exit 1 else echo "Push to origin succeeded..." fi fi fi else echo "Not 'auto' branch, will not merge or publish..." fi } upload_filesguid-create-0.5.2/renovate.json000064400000000000000000000001561046102023000145410ustar 00000000000000{ "extends": [ "config:base" ], "separateMinorPatch": true, "patch": { "enabled": false } } guid-create-0.5.2/src/lib.rs000064400000000000000000000345151046102023000137340ustar 00000000000000#![cfg_attr(not(feature = "std"), no_std)] //! # guid-create //! //! Rust helper for randomly creating GUIDs. //! //! ```rust,ignore //! extern crate guid_create; //! use guid_create::GUID; //! //! // Create GUIDs //! let guid = GUID::rand(); //! let guid = GUID::parse("87935CDE-7094-4C2B-A0F4-DD7D512DD261").unwrap(); //! let guid = GUID::build_from_components(0x87935CDE, 0x7094, 0x4C2B, &[0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61], ); //! let guid = GUID::build_from_slice(&[ 0x87, 0x93, 0x5C, 0xDE, 0x70, 0x94, 0x4C, 0x2B, 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61,]); //! //! // View GUIDs //! guid.to_string(); // 87935CDE-7094-4C2B-A0F4-DD7D512DD261 //! //! // Check GUIDs //! guid.data1(); //! guid.data2(); //! guid.data3(); //! guid.data4(); //! ``` #[cfg(test)] extern crate quickcheck; #[cfg(test)] #[macro_use(quickcheck)] extern crate quickcheck_macros; use core::{convert::TryInto, fmt}; #[cfg(windows)] use winapi::shared::guiddef::GUID as WinGuid; /// Parsing error type. #[derive(Debug)] pub struct ParseError; impl fmt::Display for ParseError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "Malformed GUID, expecting XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" ) } } impl core::error::Error for ParseError {} /// A GUID backed by 16 byte array. #[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Hash)] #[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))] #[repr(transparent)] pub struct GUID { data: [u8; 16], } impl From for GUID { fn from(item: CGuid) -> Self { GUID::build_from_components(item.a, item.b, item.c, &item.d) } } impl From for CGuid { fn from(item: GUID) -> Self { CGuid { a: item.data1(), b: item.data2(), c: item.data3(), d: item.data4(), } } } impl fmt::Display for CGuid { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let guid: GUID = (*self).into(); guid.fmt(f) } } #[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Hash)] #[repr(C)] pub struct CGuid { /// The low field of the timestamp. a: u32, /// The middle field of the timestamp. b: u16, /// The high field of the timestamp multiplexed with the version number. c: u16, /// Contains, in this order: /// - The high field of the clock sequence multiplexed with the variant. /// - The low field of the clock sequence. /// - The spatially unique node identifier. d: [u8; 8], } impl GUID { /// Construct a `GUID` from components. /// /// ``` rust /// let guid = guid_create::GUID::build_from_components( /// 0x87935CDE, /// 0x7094, /// 0x4C2B, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// assert_eq!(guid.data1(), 0x87935CDE); /// assert_eq!(guid.data2(), 0x7094); /// assert_eq!(guid.data3(), 0x4C2B); /// assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]); /// assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261"); /// ``` pub const fn build_from_components(d1: u32, d2: u16, d3: u16, d4: &[u8; 8]) -> Self { let d1 = d1.to_be_bytes(); let d2 = d2.to_be_bytes(); let d3 = d3.to_be_bytes(); #[rustfmt::skip] let data = [ d1[0], d1[1], d1[2], d1[3], d2[0], d2[1], d3[0], d3[1], d4[0], d4[1], d4[2], d4[3], d4[4], d4[5], d4[6], d4[7], ]; GUID { data } } /// Construct a `GUID` from 16 bytes. /// /// ``` rust /// let guid = guid_create::GUID::build_from_slice(&[ /// 0x87, 0x93, 0x5C, 0xDE, 0x70, 0x94, 0x4C, 0x2B, 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, /// 0xD2, 0x61, /// ]); /// /// assert_eq!(guid.data1(), 0x87935CDE); /// assert_eq!(guid.data2(), 0x7094); /// assert_eq!(guid.data3(), 0x4C2B); /// assert_eq!( /// guid.data4(), /// [0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61] /// ); /// assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261"); /// ``` pub const fn build_from_slice(data: &[u8; 16]) -> Self { GUID { data: *data } } /// Construct a `GUID` from a string. /// /// ``` rust /// let guid = guid_create::GUID::parse("87935CDE-7094-4C2B-A0F4-DD7D512DD261").unwrap(); /// /// assert_eq!(guid.data1(), 0x87935CDE); /// assert_eq!(guid.data2(), 0x7094); /// assert_eq!(guid.data3(), 0x4C2B); /// assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]); /// assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261"); /// ``` pub fn parse(guid: &str) -> Result { fn n(ch: u8) -> Result { match ch { b'0'..=b'9' => Ok(ch - 48), b'A'..=b'F' => Ok(ch - 55), b'a'..=b'f' => Ok(ch - 87), _ => Err(ParseError), } } fn hexbyte(s: &[u8]) -> Result<(u8, &[u8]), ParseError> { match s { [a, b, tail @ ..] => n(*a) .and_then(|a| n(*b).map(|b| a * 16 + b)) .map(|x| (x, tail)), _ => Err(ParseError), } } fn strip_dash(s: &[u8]) -> Result<&[u8], ParseError> { match s { [b'-', tail @ ..] => Ok(tail), _ => Err(ParseError), } } let mut data = [0u8; 16]; let mut s = guid.as_bytes(); fn fill<'a>(buf: &mut [u8], mut s: &'a [u8]) -> Result<&'a [u8], ParseError> { for l in buf { let (d, s_) = hexbyte(s)?; *l = d; s = s_; } Ok(s) } // first four bytes s = fill(&mut data[..4], s)?; s = strip_dash(s)?; // second two bytes s = fill(&mut data[4..6], s)?; s = strip_dash(s)?; // third two bytes s = fill(&mut data[6..8], s)?; s = strip_dash(s)?; // fourth two bytes s = fill(&mut data[8..10], s)?; s = strip_dash(s)?; // trailing bytes s = fill(&mut data[10..], s)?; // should be empty! if s.is_empty() { Ok(Self { data }) } else { Err(ParseError) } } /// Generates a new GUID with 16 random bytes. #[cfg(feature = "rand")] pub fn rand() -> GUID { GUID { data: rand::random(), } } /// The first four bytes. /// /// ``` rust /// extern crate guid_create; /// let guid = guid_create::GUID::build_from_components( /// 500, /// 600, /// 700, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// assert_eq!(guid.data1(), 500); /// ``` pub fn data1(&self) -> u32 { u32::from_be_bytes( self.data[0..4] .try_into() .expect("slice with incorrect length"), ) } /// Bytes 5 and 6. /// /// ``` rust /// extern crate guid_create; /// let guid = guid_create::GUID::build_from_components( /// 500, /// 600, /// 700, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// assert_eq!(guid.data2(), 600); /// ``` pub fn data2(&self) -> u16 { u16::from_be_bytes( self.data[4..6] .try_into() .expect("slice with incorrect length"), ) } /// Bytes 7 and 8. /// /// ``` rust /// extern crate guid_create; /// let guid = guid_create::GUID::build_from_components( /// 500, /// 600, /// 700, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// assert_eq!(guid.data3(), 700); /// ``` pub fn data3(&self) -> u16 { u16::from_be_bytes( self.data[6..8] .try_into() .expect("slice with incorrect length"), ) } /// The last eight bytes. /// /// ``` rust /// extern crate guid_create; /// let guid = guid_create::GUID::build_from_components( /// 500, /// 600, /// 700, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// assert_eq!( /// guid.data4(), /// [0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61] /// ); /// ``` pub fn data4(&self) -> [u8; 8] { self.data[8..16] .try_into() .expect("slice with incorrect length") } /// Convert the `GUID` to a `winapi` [GUID](https://docs.rs/winapi/0.3.4/x86_64-pc-windows-msvc/winapi/shared/guiddef/struct.GUID.html) /// > Only present on windows targets /// /// ``` rust /// extern crate guid_create; /// let guid = guid_create::GUID::build_from_components( /// 0x87935CDE, /// 0x7094, /// 0x4C2B, /// &[ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// ); /// /// let win = guid.as_winapi_guid(); /// assert_eq!(win.Data1, 0x87935CDE); /// assert_eq!(win.Data2, 0x7094); /// assert_eq!(win.Data3, 0x4C2B); /// assert_eq!(win.Data4, [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]); /// ``` #[cfg(windows)] pub fn as_winapi_guid(&self) -> WinGuid { WinGuid { Data1: self.data1(), Data2: self.data2(), Data3: self.data3(), Data4: self.data4(), } } /// Convert a `winapi` [GUID](https://docs.rs/winapi/0.3.4/x86_64-pc-windows-msvc/winapi/shared/guiddef/struct.GUID.html) to a `GUID` /// > Only present on windows targets /// /// ``` rust /// extern crate guid_create; /// extern crate winapi; /// let win = winapi::shared::guiddef::GUID { /// Data1: 0x87935CDE, /// Data2: 0x7094, /// Data3: 0x4C2B, /// Data4: [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ] /// }; /// /// let guid = guid_create::GUID::from_winapi_guid(win); /// assert_eq!(guid.data1(), 0x87935CDE); /// assert_eq!(guid.data2(), 0x7094); /// assert_eq!(guid.data3(), 0x4C2B); /// assert_eq!(guid.data4(), [ 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61 ]); /// ``` #[cfg(windows)] pub fn from_winapi_guid(guid: WinGuid) -> Self { GUID::build_from_components(guid.Data1, guid.Data2, guid.Data3, &guid.Data4) } } #[cfg(feature = "serde")] use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "serde")] impl<'de> Deserialize<'de> for GUID { fn deserialize(deserializer: D) -> Result where D: Deserializer<'de>, { let string_guid = String::deserialize(deserializer)?; let guid = GUID::parse(&string_guid) .map_err(|_| de::Error::custom(format!("cannot convert {string_guid} to guid")))?; Ok(guid) } } #[cfg(feature = "serde")] impl Serialize for GUID { fn serialize(&self, serializer: S) -> Result { serializer.serialize_str(&*self.to_string()) } } impl fmt::Display for GUID { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, "{:08X}-{:04X}-{:04X}-{:04X}-{:08X}{:04X}", self.data1(), self.data2(), self.data3(), u16::from_be_bytes([self.data[8], self.data[9]]), u32::from_be_bytes([self.data[10], self.data[11], self.data[12], self.data[13]]), u16::from_be_bytes([self.data[14], self.data[15]]), ) } } #[cfg(test)] impl quickcheck::Arbitrary for GUID { fn arbitrary(g: &mut quickcheck::Gen) -> Self { let mut data = [0u8; 16]; data.fill_with(|| u8::arbitrary(g)); Self { data } } } #[cfg(test)] mod tests { use super::*; #[test] fn travis_test() {} #[test] #[cfg(feature = "std")] fn string_lengths() { for _ in 0..10000 { let guid = GUID::rand(); let s = guid.to_string(); println!("{}", s); assert_eq!(s.len(), 36); } } #[cfg(windows)] #[test] fn win_guid() { for _ in 0..10000 { let guid = GUID::rand(); let win = guid.as_winapi_guid(); assert_eq!(guid.data1(), win.Data1); assert_eq!(guid.data2(), win.Data2); assert_eq!(guid.data3(), win.Data3); assert_eq!(guid.data4(), win.Data4); let convert_back = GUID::from_winapi_guid(win); assert_eq!(guid, convert_back); } } #[test] #[cfg(feature = "std")] fn create_from_components() { let guid = GUID::build_from_components( 0x87935CDE, 0x7094, 0x4C2B, &[0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61], ); assert_eq!(guid.data1(), 0x87935CDE); assert_eq!(guid.data2(), 0x7094); assert_eq!(guid.data3(), 0x4C2B); assert_eq!( guid.data4(), [0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61] ); assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261"); } #[test] #[cfg(feature = "std")] fn create_from_array() { let guid = GUID::build_from_slice(&[ 0x87, 0x93, 0x5C, 0xDE, 0x70, 0x94, 0x4C, 0x2B, 0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61, ]); println!("{}", guid); assert_eq!(guid.data1(), 0x87935CDE); assert_eq!(guid.data2(), 0x7094); assert_eq!(guid.data3(), 0x4C2B); assert_eq!( guid.data4(), [0xA0, 0xF4, 0xDD, 0x7D, 0x51, 0x2D, 0xD2, 0x61] ); assert_eq!(guid.to_string(), "87935CDE-7094-4C2B-A0F4-DD7D512DD261"); } #[test] #[cfg(feature = "std")] fn parse_strings() { for _ in 0..10000 { let guid = GUID::rand(); let s = guid.to_string(); let guid2 = GUID::parse(&s).unwrap(); assert_eq!(guid, guid2); } } #[quickcheck] #[cfg(feature = "std")] fn no_panic_parse(s: String) { GUID::parse(&s).ok(); } #[quickcheck] #[cfg(feature = "std")] fn parse_success(guid: GUID) -> bool { let s = guid.to_string(); let g2 = GUID::parse(&s).unwrap(); g2 == guid } }