mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1852209 - Switch to bitflags 2 r=supply-chain-reviewers,emilio
We currently are using a fake bitflags 2, derived from bitflags 1. More and more crates are using it, and we're at a sweet spot where flipping things around makes sense: using a fake bitflags 1, derived from bitflags 2. Differential Revision: https://phabricator.services.mozilla.com/D189316
This commit is contained in:
parent
e963564f60
commit
1ce83241da
91
Cargo.lock
generated
91
Cargo.lock
generated
@ -43,7 +43,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "8512c9117059663fb5606788fbca3619e2a91dac0e3fe516242eab1fa6be5e44"
|
checksum = "8512c9117059663fb5606788fbca3619e2a91dac0e3fe516242eab1fa6be5e44"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alsa-sys",
|
"alsa-sys",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"libc",
|
"libc",
|
||||||
"nix 0.24.99",
|
"nix 0.24.99",
|
||||||
]
|
]
|
||||||
@ -224,7 +224,7 @@ version = "0.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c41dc008c1973ce58ff3cfc52df53814a9b7b78d73d95b071b5ff0ed4b2db3e1"
|
checksum = "c41dc008c1973ce58ff3cfc52df53814a9b7b78d73d95b071b5ff0ed4b2db3e1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -301,7 +301,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2a46aebc9de6a88556552bc40e5ffbd479705cc0ab46fee0dec476dc2886eb13"
|
checksum = "2a46aebc9de6a88556552bc40e5ffbd479705cc0ab46fee0dec476dc2886eb13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.3",
|
"base64 0.21.3",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"devd-rs",
|
"devd-rs",
|
||||||
@ -422,7 +422,7 @@ version = "0.66.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
|
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"cexpr",
|
"cexpr",
|
||||||
"clang-sys",
|
"clang-sys",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -453,15 +453,18 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "1.999.999"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
dependencies = [
|
||||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
"bitflags 2.4.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.999.999"
|
version = "2.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -753,7 +756,7 @@ version = "4.1.14"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "351f9ad9688141ed83dfd8f5fb998a06225ef444b48ff4dc43de6d409b7fd10b"
|
checksum = "351f9ad9688141ed83dfd8f5fb998a06225ef444b48ff4dc43de6d409b7fd10b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"clap_lex",
|
"clap_lex",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"strsim",
|
"strsim",
|
||||||
@ -833,7 +836,7 @@ version = "0.23.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"
|
checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
@ -846,7 +849,7 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33"
|
checksum = "2bb142d41022986c1d8ff29103a1411c8a3dfad3552f87a4f8dc50d61d4f4e33"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"core-foundation",
|
"core-foundation",
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@ -1081,7 +1084,7 @@ version = "0.10.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4727331fcc9ab77948fe80166f99657290d09589ca0a6e0a948f63c790f09584"
|
checksum = "4727331fcc9ab77948fe80166f99657290d09589ca0a6e0a948f63c790f09584"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"cubeb-sys",
|
"cubeb-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1092,7 +1095,7 @@ source = "git+https://github.com/mozilla/cubeb-coreaudio-rs?rev=93b5c01a131f65c8
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atomic",
|
"atomic",
|
||||||
"audio-mixer",
|
"audio-mixer",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"coreaudio-sys-utils",
|
"coreaudio-sys-utils",
|
||||||
"cubeb-backend",
|
"cubeb-backend",
|
||||||
"float-cmp",
|
"float-cmp",
|
||||||
@ -1131,7 +1134,7 @@ version = "0.7.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20"
|
checksum = "e16e44ab292b1dddfdaf7be62cfd8877df52f2f3fde5858d95bab606be259f20"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"libloading",
|
"libloading",
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
@ -1412,7 +1415,7 @@ dependencies = [
|
|||||||
name = "dom"
|
name = "dom"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1861,7 +1864,7 @@ version = "0.3.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"fuchsia-zircon-sys",
|
"fuchsia-zircon-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2358,7 +2361,7 @@ version = "0.6.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171"
|
checksum = "fbcd2dba93594b227a1f57ee09b8b9da8892c34d55aa332e034a228d0fe6a171"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"gpu-alloc-types",
|
"gpu-alloc-types",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2368,7 +2371,7 @@ version = "0.3.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4"
|
checksum = "98ff03b468aa837d70984d55f5d3f846f6ec31fe34bbb97c4f85219caeee1ca4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -2377,7 +2380,7 @@ version = "0.2.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a"
|
checksum = "0b0c02e1ba0bdb14e965058ca34e09c020f8e507a760df1121728e0aef68d57a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"gpu-descriptor-types",
|
"gpu-descriptor-types",
|
||||||
"hashbrown",
|
"hashbrown",
|
||||||
]
|
]
|
||||||
@ -2388,7 +2391,7 @@ version = "0.1.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126"
|
checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -3153,7 +3156,7 @@ version = "0.14.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b"
|
checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"libc",
|
"libc",
|
||||||
"lmdb-rkv-sys",
|
"lmdb-rkv-sys",
|
||||||
@ -3350,7 +3353,7 @@ name = "metal"
|
|||||||
version = "0.26.0"
|
version = "0.26.0"
|
||||||
source = "git+https://github.com/gfx-rs/metal-rs/?rev=d24f1a4#d24f1a4ae92470bf87a0c65ecfe78c9299835505"
|
source = "git+https://github.com/gfx-rs/metal-rs/?rev=d24f1a4#d24f1a4ae92470bf87a0c65ecfe78c9299835505"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"block",
|
"block",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"foreign-types",
|
"foreign-types",
|
||||||
@ -3365,7 +3368,7 @@ version = "0.7.0"
|
|||||||
source = "git+https://github.com/mozilla/midir.git?rev=519e651241e867af3391db08f9ae6400bc023e18#519e651241e867af3391db08f9ae6400bc023e18"
|
source = "git+https://github.com/mozilla/midir.git?rev=519e651241e867af3391db08f9ae6400bc023e18#519e651241e867af3391db08f9ae6400bc023e18"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"alsa",
|
"alsa",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"coremidi",
|
"coremidi",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"libc",
|
"libc",
|
||||||
@ -3415,7 +3418,7 @@ name = "minidump-common"
|
|||||||
version = "0.17.0"
|
version = "0.17.0"
|
||||||
source = "git+https://github.com/rust-minidump/rust-minidump?rev=6ae42a7f992e8a88ebee661bc77bcedb95cd671f#6ae42a7f992e8a88ebee661bc77bcedb95cd671f"
|
source = "git+https://github.com/rust-minidump/rust-minidump?rev=6ae42a7f992e8a88ebee661bc77bcedb95cd671f#6ae42a7f992e8a88ebee661bc77bcedb95cd671f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"debugid",
|
"debugid",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
@ -3429,7 +3432,7 @@ name = "minidump-writer"
|
|||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
source = "git+https://github.com/rust-minidump/minidump-writer.git?rev=491eb330e78e310c32927e5cc3bd2350af1e93f8#491eb330e78e310c32927e5cc3bd2350af1e93f8"
|
source = "git+https://github.com/rust-minidump/minidump-writer.git?rev=491eb330e78e310c32927e5cc3bd2350af1e93f8#491eb330e78e310c32927e5cc3bd2350af1e93f8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"crash-context",
|
"crash-context",
|
||||||
@ -3727,7 +3730,7 @@ version = "0.13.0"
|
|||||||
source = "git+https://github.com/gfx-rs/naga?rev=df8107b7#df8107b78812cc2b1e3d5de35279cedc1f0da3fb"
|
source = "git+https://github.com/gfx-rs/naga?rev=df8107b7#df8107b78812cc2b1e3d5de35279cedc1f0da3fb"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit-set",
|
"bit-set",
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"codespan-reporting",
|
"codespan-reporting",
|
||||||
"hexf-parse",
|
"hexf-parse",
|
||||||
"indexmap 2.999.999",
|
"indexmap 2.999.999",
|
||||||
@ -3873,7 +3876,7 @@ version = "0.26.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
|
checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"cfg-if 1.0.0",
|
"cfg-if 1.0.0",
|
||||||
"libc",
|
"libc",
|
||||||
"static_assertions",
|
"static_assertions",
|
||||||
@ -3921,7 +3924,7 @@ source = "git+https://github.com/mozilla/application-services?rev=1a59041d0c7d36
|
|||||||
name = "nsstring"
|
name = "nsstring"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"encoding_rs",
|
"encoding_rs",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -4352,7 +4355,7 @@ version = "0.16.0-RC1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ee00a90a41543fce203e6a8771bad043bfd6d88de8fd4e3118435a233d0c3c4"
|
checksum = "8ee00a90a41543fce203e6a8771bad043bfd6d88de8fd4e3118435a233d0c3c4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"hex",
|
"hex",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -4408,7 +4411,7 @@ name = "pulse"
|
|||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+https://github.com/mozilla/cubeb-pulse-rs?rev=cf48897be5cbe147d051ebbbe1eaf5fd8fb6bbc9#cf48897be5cbe147d051ebbbe1eaf5fd8fb6bbc9"
|
source = "git+https://github.com/mozilla/cubeb-pulse-rs?rev=cf48897be5cbe147d051ebbbe1eaf5fd8fb6bbc9#cf48897be5cbe147d051ebbbe1eaf5fd8fb6bbc9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"pulse-ffi",
|
"pulse-ffi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -4603,7 +4606,7 @@ checksum = "9f0ea3af1393b22f8fe25615b6fa5d13072b7b622e66acffc8b12b2baa0342b1"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayref",
|
"arrayref",
|
||||||
"bincode",
|
"bincode",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"id-arena",
|
"id-arena",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -4625,7 +4628,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64 0.21.3",
|
"base64 0.21.3",
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
@ -4668,7 +4671,7 @@ version = "0.29.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2"
|
checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"fallible-iterator",
|
"fallible-iterator",
|
||||||
"fallible-streaming-iterator",
|
"fallible-streaming-iterator",
|
||||||
"hashlink",
|
"hashlink",
|
||||||
@ -4794,7 +4797,7 @@ dependencies = [
|
|||||||
name = "selectors"
|
name = "selectors"
|
||||||
version = "0.22.0"
|
version = "0.22.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
"derive_more 0.99.999",
|
"derive_more 0.99.999",
|
||||||
"fxhash",
|
"fxhash",
|
||||||
@ -5071,7 +5074,7 @@ version = "0.2.0+1.5.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830"
|
checksum = "246bfa38fe3db3f1dfc8ca5a2cdeb7348c78be2112740cc0ec8ef18b6d94f830"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -5161,7 +5164,7 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"atomic_refcell",
|
"atomic_refcell",
|
||||||
"bindgen 0.66.1",
|
"bindgen 0.66.1",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
"derive_more 0.99.999",
|
"derive_more 0.99.999",
|
||||||
@ -5228,7 +5231,7 @@ name = "style_traits"
|
|||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
"euclid",
|
"euclid",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -6191,7 +6194,7 @@ name = "webrender"
|
|||||||
version = "0.62.0"
|
version = "0.62.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bincode",
|
"bincode",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"build-parallel",
|
"build-parallel",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"derive_more 0.99.999",
|
"derive_more 0.99.999",
|
||||||
@ -6228,7 +6231,7 @@ name = "webrender_api"
|
|||||||
version = "0.62.0"
|
version = "0.62.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"euclid",
|
"euclid",
|
||||||
@ -6275,7 +6278,7 @@ dependencies = [
|
|||||||
name = "webrender_build"
|
name = "webrender_build"
|
||||||
version = "0.0.2"
|
version = "0.0.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.3.2",
|
"bitflags 1.999.999",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
@ -6306,7 +6309,7 @@ source = "git+https://github.com/gfx-rs/wgpu?rev=7e0d6c971f900f6a8f01a9de9c41f78
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arrayvec",
|
"arrayvec",
|
||||||
"bit-vec",
|
"bit-vec",
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"codespan-reporting",
|
"codespan-reporting",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
@ -6331,7 +6334,7 @@ dependencies = [
|
|||||||
"arrayvec",
|
"arrayvec",
|
||||||
"ash",
|
"ash",
|
||||||
"bit-set",
|
"bit-set",
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"block",
|
"block",
|
||||||
"core-graphics-types",
|
"core-graphics-types",
|
||||||
"d3d12",
|
"d3d12",
|
||||||
@ -6363,7 +6366,7 @@ name = "wgpu-types"
|
|||||||
version = "0.17.0"
|
version = "0.17.0"
|
||||||
source = "git+https://github.com/gfx-rs/wgpu?rev=7e0d6c971f900f6a8f01a9de9c41f7894164a82c#7e0d6c971f900f6a8f01a9de9c41f7894164a82c"
|
source = "git+https://github.com/gfx-rs/wgpu?rev=7e0d6c971f900f6a8f01a9de9c41f7894164a82c#7e0d6c971f900f6a8f01a9de9c41f7894164a82c"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 2.999.999",
|
"bitflags 2.4.0",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"serde",
|
"serde",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.999.999"
|
version = "1.999.999"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
path = "lib.rs"
|
||||||
|
|
||||||
[features]
|
|
||||||
serde = []
|
|
||||||
|
|
||||||
[dependencies.bitflags]
|
[dependencies.bitflags]
|
||||||
version = "1.0"
|
version = "2"
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
pub use bitflags::*;
|
pub use bitflags::bitflags as bitflags2;
|
||||||
|
|
||||||
// Copy of the macro from bitflags 1.3.2, with the implicit derives
|
// Copy of the macro from bitflags 1.3.2, with the implicit derives
|
||||||
// removed, because in 2.0, they're expected to be explicitly given
|
// removed, because in 2.0, they're expected to be explicitly given
|
||||||
@ -29,97 +29,22 @@ macro_rules! bitflags {
|
|||||||
|
|
||||||
$($t:tt)*
|
$($t:tt)*
|
||||||
) => {
|
) => {
|
||||||
__impl_bitflags_remove_derive_debug! {
|
$(#[$($outer)+])*
|
||||||
$(#[$($outer)+])*
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
$vis struct $BitFlags($T);
|
||||||
|
|
||||||
$vis struct $BitFlags {
|
bitflags2! {
|
||||||
bits: $T,
|
impl $BitFlags: $T {
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
__impl_bitflags! {
|
|
||||||
$BitFlags: $T {
|
|
||||||
$(
|
$(
|
||||||
$(#[$inner $($args)*])*
|
$(#[$inner $($args)*])*
|
||||||
$Flag = $value;
|
const $Flag = $value;
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $BitFlags {
|
|
||||||
/// Convert from underlying bit representation, preserving all
|
|
||||||
/// bits (even those not corresponding to a defined flag).
|
|
||||||
#[inline]
|
|
||||||
pub const fn from_bits_retain(bits: $T) -> Self {
|
|
||||||
Self { bits }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
$($t)*
|
$($t)*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
() => {};
|
() => {};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export(local_inner_macros)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
macro_rules! __impl_bitflags_remove_derive_debug {
|
|
||||||
(
|
|
||||||
$(@ $(#[$keep_outer:meta])* @)?
|
|
||||||
#[derive(@ $($keep_derives:ident),+ @)]
|
|
||||||
$(#[$($other_outer:tt)+])*
|
|
||||||
$vis:vis struct $BitFlags:ident { $($t:tt)* }
|
|
||||||
) => {
|
|
||||||
__impl_bitflags_remove_derive_debug! {
|
|
||||||
@ $($(#[$keep_outer])*)? #[derive($($keep_derives),+)] @
|
|
||||||
$(#[$($other_outer)+])*
|
|
||||||
$vis struct $BitFlags { $($t)* }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
(
|
|
||||||
$(@ $(#[$keep_outer:meta])* @)?
|
|
||||||
#[derive($(@ $($keep_derives:ident),+ @)? Debug $(,$derives:ident)*)]
|
|
||||||
$(#[$($other_outer:tt)+])*
|
|
||||||
$vis:vis struct $BitFlags:ident { $($t:tt)* }
|
|
||||||
) => {
|
|
||||||
__impl_bitflags_remove_derive_debug! {
|
|
||||||
@ $($(#[$keep_outer])*)? @
|
|
||||||
#[derive($(@ $($keep_derives),+ @)? $($derives),*)]
|
|
||||||
$(#[$($other_outer)+])*
|
|
||||||
$vis struct $BitFlags { $($t)* }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
(
|
|
||||||
$(@ $(#[$keep_outer:meta])* @)?
|
|
||||||
#[derive($(@ $($keep_derives:ident),+ @)? $derive:ident $(,$derives:ident)*)]
|
|
||||||
$(#[$($other_outer:tt)+])*
|
|
||||||
$vis:vis struct $BitFlags:ident { $($t:tt)* }
|
|
||||||
) => {
|
|
||||||
__impl_bitflags_remove_derive_debug! {
|
|
||||||
@ $($(#[$keep_outer])*)? @
|
|
||||||
#[derive(@ $($($keep_derives,)+)? $derive @ $($derives),*)]
|
|
||||||
$(#[$($other_outer)+])*
|
|
||||||
$vis struct $BitFlags { $($t)* }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
(
|
|
||||||
$(@ $(#[$keep_outer:meta])* @)?
|
|
||||||
#[$outer:meta]
|
|
||||||
$(#[$($other_outer:tt)+])*
|
|
||||||
$vis:vis struct $BitFlags:ident { $($t:tt)* }
|
|
||||||
) => {
|
|
||||||
__impl_bitflags_remove_derive_debug! {
|
|
||||||
@ $($(#[$keep_outer])*)? #[$outer] @
|
|
||||||
$(#[$($other_outer)+])*
|
|
||||||
$vis struct $BitFlags { $($t)* }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
(
|
|
||||||
@ $(#[$keep_outer:meta])* @
|
|
||||||
$vis:vis struct $BitFlags:ident { $($t:tt)* }
|
|
||||||
) => {
|
|
||||||
$(#[$keep_outer])*
|
|
||||||
$vis struct $BitFlags { $($t)* }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
@ -709,6 +709,11 @@ who = "Teodor Tanasoaia <ttanasoaia@mozilla.com>"
|
|||||||
criteria = "safe-to-deploy"
|
criteria = "safe-to-deploy"
|
||||||
delta = "2.2.1 -> 2.3.2"
|
delta = "2.2.1 -> 2.3.2"
|
||||||
|
|
||||||
|
[[audits.bitflags]]
|
||||||
|
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||||
|
criteria = "safe-to-deploy"
|
||||||
|
delta = "2.3.3 -> 2.4.0"
|
||||||
|
|
||||||
[[audits.block-buffer]]
|
[[audits.block-buffer]]
|
||||||
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
who = "Mike Hommey <mh+mozilla@glandium.org>"
|
||||||
criteria = "safe-to-deploy"
|
criteria = "safe-to-deploy"
|
||||||
|
@ -805,6 +805,25 @@ criteria = "safe-to-deploy"
|
|||||||
version = "0.21.0"
|
version = "0.21.0"
|
||||||
notes = "This crate has no dependencies, no build.rs, and contains no unsafe code."
|
notes = "This crate has no dependencies, no build.rs, and contains no unsafe code."
|
||||||
|
|
||||||
|
[[audits.bytecode-alliance.audits.bitflags]]
|
||||||
|
who = "Jamey Sharp <jsharp@fastly.com>"
|
||||||
|
criteria = "safe-to-deploy"
|
||||||
|
delta = "2.1.0 -> 2.2.1"
|
||||||
|
notes = """
|
||||||
|
This version adds unsafe impls of traits from the bytemuck crate when built
|
||||||
|
with that library enabled, but I believe the impls satisfy the documented
|
||||||
|
safety requirements for bytemuck. The other changes are minor.
|
||||||
|
"""
|
||||||
|
|
||||||
|
[[audits.bytecode-alliance.audits.bitflags]]
|
||||||
|
who = "Alex Crichton <alex@alexcrichton.com>"
|
||||||
|
criteria = "safe-to-deploy"
|
||||||
|
delta = "2.3.2 -> 2.3.3"
|
||||||
|
notes = """
|
||||||
|
Nothing outside the realm of what one would expect from a bitflags generator,
|
||||||
|
all as expected.
|
||||||
|
"""
|
||||||
|
|
||||||
[[audits.bytecode-alliance.audits.block-buffer]]
|
[[audits.bytecode-alliance.audits.block-buffer]]
|
||||||
who = "Benjamin Bouvier <public@benj.me>"
|
who = "Benjamin Bouvier <public@benj.me>"
|
||||||
criteria = "safe-to-deploy"
|
criteria = "safe-to-deploy"
|
||||||
|
@ -1 +1 @@
|
|||||||
{"files":{"CHANGELOG.md":"d362fc1fccaaf4d421bcf0fe8b80ddb4f625dade0c1ee52d08bd0b95509a49d1","CODE_OF_CONDUCT.md":"42634d0f6d922f49857175af991802822f7f920487aefa2ee250a50d12251a66","Cargo.toml":"87aced7532a7974eb37ab5fe6037f0abafc36d6b2d74891ecd2bf2f14f50d11e","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"baa8604f8afb34fd93b9c79729daafb884dedcaf34023e4af8ad037d916061fd","src/example_generated.rs":"e43eb59e90f317f38d436670a6067d2fd9eb35fb319fe716184e4a04e24ed1b2","src/lib.rs":"e6477688535ee326d27238aeedc9cb4320ac35b9d17a4deda09e0587b0ccdbd4","tests/basic.rs":"146f1cbf6279bc609242cd3349f29cb21b41294f5e4921875f5ec95bd83529a2","tests/compile-fail/impls/copy.rs":"b791371237ddc75a7c04d2130e03b462c9c00a80dca08bd45aa97433d9c0d13a","tests/compile-fail/impls/copy.stderr.beta":"77d83484ce221d4b6ff2f7de843929a452d779fcfff428122710dd8218c298e3","tests/compile-fail/impls/eq.rs":"0cee8b9e07d537890e0189710293b53972d0fab63c09366f33c391065afafa99","tests/compile-fail/impls/eq.stderr.beta":"381fc6143d45ce76d7cecc47aa59cb69fe5e79c0b60a4a85d5c6163b400b3cc7","tests/compile-fail/non_integer_base/all_defined.rs":"95e14cad9e94560262f2862c3c01865ac30369b69da1001b0e7285cb55e6cb75","tests/compile-fail/non_integer_base/all_defined.stderr.beta":"1760739a276690903bb03844025587d37939f5dfcbfab309db3c86f32bdbf748","tests/compile-fail/non_integer_base/all_missing.rs":"b3d9da619d23213731ba2581aa7999c796c3c79aaf4f0ee6b11ceec08a11537f","tests/compile-fail/non_integer_base/all_missing.stderr.beta":"37e102290d3867e175b21976be798939f294efb17580d5b51e7b17b590d55132","tests/compile-fail/visibility/private_field.rs":"38e4d3fe6471829360d12c8d09b097f6a21aa93fb51eac3b215d96bdae23316b","tests/compile-fail/visibility/private_field.stderr.beta":"5aa24a3ebb39326f31927721c5017b8beb66c3e501fb865a3fa814c9763bfa0f","tests/compile-fail/visibility/private_flags.rs":"2ce4235802aa4e9c96c4e77d9e31d8401ef58dcda4741325184f0764ab1fe393","tests/compile-fail/visibility/private_flags.stderr.beta":"f3eb9f7baf2689258f3519ff7ee5c6ec3c237264ebcfe63f40c40f2023e5022f","tests/compile-fail/visibility/pub_const.rs":"8f813a97ac518c5ea8ac65b184101912452384afaf7b8d6c5e62f8370eca3c0a","tests/compile-fail/visibility/pub_const.stderr.beta":"823976ae1794d7f5372e2ec9aabba497e7bb88004722904c38da342ed98e8962","tests/compile-pass/impls/convert.rs":"88fe80bfb9cd5779f0e1d92c9ec02a8b6bb67e334c07f2309e9c0ba5ef776eb0","tests/compile-pass/impls/default.rs":"c508f9a461691f44b45142fa5ad599f02326e1de4c0cbca6c0593f4652eba109","tests/compile-pass/impls/inherent_methods.rs":"ecc26388e9a394bfa7a5bb69a5d621ab3d4d1e53f28f657bb8e78fe79f437913","tests/compile-pass/redefinition/core.rs":"ff5b6e72f87acc6ebb12405d3c0f6e3fa62e669933656a454bb63b30ea44179c","tests/compile-pass/redefinition/stringify.rs":"1edbce42b900c14425d7ffa14e83e165ebe452d7dccd8c0a8a821bdec64f5c93","tests/compile-pass/repr/c.rs":"6fda17f7c2edfcd155314579e83d0fc8a16209e400f1f9a5ca77bd9a799041f2","tests/compile-pass/repr/transparent.rs":"6cdc87a2137d8a4e0c8ce9b6cba83c82255f8ea125951bf614418685600489ce","tests/compile-pass/visibility/bits_field.rs":"1f3e5ba5a047440066a9f6bf7b7af33f5b06f6b1da3dd9af6886168199a7ea0a","tests/compile-pass/visibility/pub_in.rs":"e95312ff60966d42ec4bc00225507895a9b8ec24056ce6a9edd9145be35d730f","tests/compile.rs":"f27c67a7dd183ca30efea1b6e0880e3469a6dd63b92b1fd711c082df182c9eec"},"package":"bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"}
|
{"files":{"CHANGELOG.md":"233d0b9c9c8e2c89cd0e0dc225a3cf76c0a6fae357d2a02743fb4dff09286194","CODE_OF_CONDUCT.md":"42634d0f6d922f49857175af991802822f7f920487aefa2ee250a50d12251a66","CONTRIBUTING.md":"6c9f96eacb20af877ae2d16f024904f3038b93448a8488e9dbcac0df7f6439a5","Cargo.lock":"4db44aa18134aa14828cc0f99ff4329fbc9026dc89bb0503b9dc054d9ab62bc6","Cargo.toml":"6e552ff8a664536eb76313b23c84e895c0ce364506acace410c80d67b335a6cb","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"892ef45ec866633a928ad55f3083fe71fb5d311ea9f5ca2f4ba7d680f50ad724","SECURITY.md":"68704c8128fa2e776ed7cbda741fbf61ad52f998a96350ee7ee4dbf64c6573bc","benches/parse.rs":"f1390d62322c6880d65bd931e183d49b313f287879a6bfaa36b1cb1921090b51","examples/custom_bits_type.rs":"e53b32051adc5d97860e0b48c8f3a301a041d73b4939c0d7caa5f0cfcc0b9739","examples/custom_derive.rs":"29dd7b845345a103ca31e91b579aeb01fb74935b8223c29184eb42223edadb65","examples/fmt.rs":"87ba37a1fb8528570c74ea26d8e8948e1179c3d867b928bea1080880258e0a99","examples/macro_free.rs":"69e7f284b53b5214d51228a686e87f127b52a3b74711e45537ebfa5583a180e5","examples/serde.rs":"08b21b35d5c10fdca132fe0f36c8067bb44f559e96617a9257ab6316a20cbc75","spec.md":"fcdd939df30c59b0643be09027df664b71cbea9b9989185441482c5576160fed","src/example_generated.rs":"d018caf059f6ffc4c2403b771a6d76679fa5af03c329a91bd9252957df695e7f","src/external.rs":"11599248db17d395c6b45bf2400266f221d3eb1523908e5f17715964bf8d99ed","src/external/arbitrary.rs":"fa8c9187028b9bc54856977b0914676f62101010e7a9450abd577fd78c89552f","src/external/bytemuck.rs":"3afcef382122867040fddd5e4153d633d1ed5596fe5d7dfac66a8e61c2513df5","src/external/serde.rs":"4a09db12534a20fe554a08dc5f1c8124b379292d41fa75628abcd2ca21587573","src/internal.rs":"fd939154cbebf43bfc329a4a3cd08618ca30a6a5f6e6abea07d23f75bf5b3b2d","src/iter.rs":"dbaa6437c1c044f689185ce3fafe43df8796bed19bbdd2c20334a52de5eeee73","src/lib.rs":"28d42a2e573955ab816b937f8024f2bfc97663647558ace10914c224f4ddd296","src/parser.rs":"52f6352620ce3d5973bc38b42d56a760307294162c9d5668eb774eb92a6ef941","src/public.rs":"72b41639711bab95e8e75f37401a487088e7be1a427715cea40563fb3f64ed60","src/tests.rs":"b120c27ff0c67a819527de9d8171f1f4c5d37ba4009c54abeb869c70e6035f14","src/traits.rs":"0a8764c3e2378043e2724cf1bfc514d4ff1985026db33509f6451a7897e2675d"},"package":"b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"}
|
231
third_party/rust/bitflags/CHANGELOG.md
vendored
231
third_party/rust/bitflags/CHANGELOG.md
vendored
@ -1,8 +1,235 @@
|
|||||||
|
# 2.4.0
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Remove html_root_url by @eldruin in https://github.com/bitflags/bitflags/pull/368
|
||||||
|
* Support unnamed flags by @KodrAus in https://github.com/bitflags/bitflags/pull/371
|
||||||
|
* Update smoke test to verify all Clippy and rustc lints by @MitMaro in https://github.com/bitflags/bitflags/pull/374
|
||||||
|
* Specify the behavior of bitflags by @KodrAus in https://github.com/bitflags/bitflags/pull/369
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @eldruin made their first contribution in https://github.com/bitflags/bitflags/pull/368
|
||||||
|
* @MitMaro made their first contribution in https://github.com/bitflags/bitflags/pull/374
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.3.3...2.4.0
|
||||||
|
|
||||||
|
# 2.3.3
|
||||||
|
|
||||||
|
## Changes to `-=`
|
||||||
|
|
||||||
|
The `-=` operator was incorrectly changed to truncate bits that didn't correspond to valid flags in `2.3.0`. This has
|
||||||
|
been fixed up so it once again behaves the same as `-` and `difference`.
|
||||||
|
|
||||||
|
## Changes to `!`
|
||||||
|
|
||||||
|
The `!` operator previously called `Self::from_bits_truncate`, which would truncate any bits that only partially
|
||||||
|
overlapped with a valid flag. It will now use `bits & Self::all().bits()`, so any bits that overlap any bits
|
||||||
|
specified by any flag will be respected. This is unlikely to have any practical implications, but enables defining
|
||||||
|
a flag like `const ALL = !0` as a way to signal that any bit pattern is a known set of flags.
|
||||||
|
|
||||||
|
## Changes to formatting
|
||||||
|
|
||||||
|
Zero-valued flags will never be printed. You'll either get `0x0` for empty flags using debug formatting, or the
|
||||||
|
set of flags with zero-valued flags omitted for others.
|
||||||
|
|
||||||
|
Composite flags will no longer be redundantly printed if there are extra bits to print at the end that don't correspond
|
||||||
|
to a valid flag.
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix up incorrect sub assign behavior and other cleanups by @KodrAus in https://github.com/bitflags/bitflags/pull/366
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.3.2...2.3.3
|
||||||
|
|
||||||
|
# 2.3.2
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* [doc] [src/lib.rs] delete redundant path prefix by @OccupyMars2025 in https://github.com/bitflags/bitflags/pull/361
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @OccupyMars2025 made their first contribution in https://github.com/bitflags/bitflags/pull/361
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.3.1...2.3.2
|
||||||
|
|
||||||
|
# 2.3.1
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix Self in flags value expressions by @KodrAus in https://github.com/bitflags/bitflags/pull/355
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.3.0...2.3.1
|
||||||
|
|
||||||
|
# 2.3.0
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Support ejecting flags types from the bitflags macro by @KodrAus in https://github.com/bitflags/bitflags/pull/351
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.2.1...2.3.0
|
||||||
|
|
||||||
|
# 2.2.1
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Refactor attribute filtering to apply per-flag by @KodrAus in https://github.com/bitflags/bitflags/pull/345
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.2.0...2.2.1
|
||||||
|
|
||||||
|
# 2.2.0
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Create SECURITY.md by @KodrAus in https://github.com/bitflags/bitflags/pull/338
|
||||||
|
* add docs to describe the behavior of multi-bit flags by @nicholasbishop in https://github.com/bitflags/bitflags/pull/340
|
||||||
|
* Add support for bytemuck by @KodrAus in https://github.com/bitflags/bitflags/pull/336
|
||||||
|
* Add a top-level macro for filtering attributes by @KodrAus in https://github.com/bitflags/bitflags/pull/341
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @nicholasbishop made their first contribution in https://github.com/bitflags/bitflags/pull/340
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.1.0...2.2.0
|
||||||
|
|
||||||
|
# 2.1.0
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Add docs for the internal Field0 and examples of formatting/parsing by @KodrAus in https://github.com/bitflags/bitflags/pull/328
|
||||||
|
* Add support for arbitrary by @KodrAus in https://github.com/bitflags/bitflags/pull/324
|
||||||
|
* Fix up missing docs for consts within consts by @KodrAus in https://github.com/bitflags/bitflags/pull/330
|
||||||
|
* Ignore clippy lint in generated code by @Jake-Shadle in https://github.com/bitflags/bitflags/pull/331
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @Jake-Shadle made their first contribution in https://github.com/bitflags/bitflags/pull/331
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.0.2...2.1.0
|
||||||
|
|
||||||
|
# 2.0.2
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix up missing isize and usize Bits impls by @KodrAus in https://github.com/bitflags/bitflags/pull/321
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.0.1...2.0.2
|
||||||
|
|
||||||
|
# 2.0.1
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix up some docs issues by @KodrAus in https://github.com/bitflags/bitflags/pull/309
|
||||||
|
* Make empty_flag() const. by @tormeh in https://github.com/bitflags/bitflags/pull/313
|
||||||
|
* Fix formatting of multi-bit flags with partial overlap by @KodrAus in https://github.com/bitflags/bitflags/pull/316
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @tormeh made their first contribution in https://github.com/bitflags/bitflags/pull/313
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.0.0...2.0.1
|
||||||
|
|
||||||
|
# 2.0.0
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix a typo and call out MSRV bump by @KodrAus in https://github.com/bitflags/bitflags/pull/259
|
||||||
|
* BitFlags trait by @arturoc in https://github.com/bitflags/bitflags/pull/220
|
||||||
|
* Add a hidden trait to discourage manual impls of BitFlags by @KodrAus in https://github.com/bitflags/bitflags/pull/261
|
||||||
|
* Sanitize `Ok` by @konsumlamm in https://github.com/bitflags/bitflags/pull/266
|
||||||
|
* Fix bug in `Debug` implementation by @konsumlamm in https://github.com/bitflags/bitflags/pull/268
|
||||||
|
* Fix a typo in the generated documentation by @wackbyte in https://github.com/bitflags/bitflags/pull/271
|
||||||
|
* Use SPDX license format by @atouchet in https://github.com/bitflags/bitflags/pull/272
|
||||||
|
* serde tests fail in CI by @arturoc in https://github.com/bitflags/bitflags/pull/277
|
||||||
|
* Fix beta test output by @KodrAus in https://github.com/bitflags/bitflags/pull/279
|
||||||
|
* Add example to the README.md file by @tiaanl in https://github.com/bitflags/bitflags/pull/270
|
||||||
|
* Iterator over all the enabled options by @arturoc in https://github.com/bitflags/bitflags/pull/278
|
||||||
|
* from_bits_(truncate) fail with composite flags by @arturoc in https://github.com/bitflags/bitflags/pull/276
|
||||||
|
* Add more platform coverage to CI by @KodrAus in https://github.com/bitflags/bitflags/pull/280
|
||||||
|
* rework the way cfgs are handled by @KodrAus in https://github.com/bitflags/bitflags/pull/281
|
||||||
|
* Split generated code into two types by @KodrAus in https://github.com/bitflags/bitflags/pull/282
|
||||||
|
* expose bitflags iters using nameable types by @KodrAus in https://github.com/bitflags/bitflags/pull/286
|
||||||
|
* Support creating flags from their names by @KodrAus in https://github.com/bitflags/bitflags/pull/287
|
||||||
|
* Update README.md by @KodrAus in https://github.com/bitflags/bitflags/pull/288
|
||||||
|
* Prepare for 2.0.0-rc.1 release by @KodrAus in https://github.com/bitflags/bitflags/pull/289
|
||||||
|
* Add missing "if" to contains doc-comment in traits.rs by @rusty-snake in https://github.com/bitflags/bitflags/pull/291
|
||||||
|
* Forbid unsafe_code by @fintelia in https://github.com/bitflags/bitflags/pull/294
|
||||||
|
* serde: enable no-std support by @nim65s in https://github.com/bitflags/bitflags/pull/296
|
||||||
|
* Add a parser for flags formatted as bar-separated-values by @KodrAus in https://github.com/bitflags/bitflags/pull/297
|
||||||
|
* Prepare for 2.0.0-rc.2 release by @KodrAus in https://github.com/bitflags/bitflags/pull/299
|
||||||
|
* Use strip_prefix instead of starts_with + slice by @QuinnPainter in https://github.com/bitflags/bitflags/pull/301
|
||||||
|
* Fix up some clippy lints by @KodrAus in https://github.com/bitflags/bitflags/pull/302
|
||||||
|
* Prepare for 2.0.0-rc.3 release by @KodrAus in https://github.com/bitflags/bitflags/pull/303
|
||||||
|
* feat: Add minimum permissions to rust.yml workflow by @gabibguti in https://github.com/bitflags/bitflags/pull/305
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @wackbyte made their first contribution in https://github.com/bitflags/bitflags/pull/271
|
||||||
|
* @atouchet made their first contribution in https://github.com/bitflags/bitflags/pull/272
|
||||||
|
* @tiaanl made their first contribution in https://github.com/bitflags/bitflags/pull/270
|
||||||
|
* @rusty-snake made their first contribution in https://github.com/bitflags/bitflags/pull/291
|
||||||
|
* @fintelia made their first contribution in https://github.com/bitflags/bitflags/pull/294
|
||||||
|
* @nim65s made their first contribution in https://github.com/bitflags/bitflags/pull/296
|
||||||
|
* @QuinnPainter made their first contribution in https://github.com/bitflags/bitflags/pull/301
|
||||||
|
* @gabibguti made their first contribution in https://github.com/bitflags/bitflags/pull/305
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/1.3.2...2.0.0
|
||||||
|
|
||||||
|
# 2.0.0-rc.3
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Use strip_prefix instead of starts_with + slice by @QuinnPainter in https://github.com/bitflags/bitflags/pull/301
|
||||||
|
* Fix up some clippy lints by @KodrAus in https://github.com/bitflags/bitflags/pull/302
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @QuinnPainter made their first contribution in https://github.com/bitflags/bitflags/pull/301
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.0.0-rc.2...2.0.0-rc.3
|
||||||
|
|
||||||
|
# 2.0.0-rc.2
|
||||||
|
|
||||||
|
## Changes to `serde` serialization
|
||||||
|
|
||||||
|
**⚠️ NOTE ⚠️** This release changes the default serialization you'll get if you `#[derive(Serialize, Deserialize)]`
|
||||||
|
on your generated flags types. It will now use a formatted string for human-readable formats and the underlying bits
|
||||||
|
type for compact formats.
|
||||||
|
|
||||||
|
To keep the old behavior, see the [`bitflags-serde-legacy`](https://github.com/KodrAus/bitflags-serde-legacy) library.
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
|
||||||
|
* Add missing "if" to contains doc-comment in traits.rs by @rusty-snake in https://github.com/bitflags/bitflags/pull/291
|
||||||
|
* Forbid unsafe_code by @fintelia in https://github.com/bitflags/bitflags/pull/294
|
||||||
|
* serde: enable no-std support by @nim65s in https://github.com/bitflags/bitflags/pull/296
|
||||||
|
* Add a parser for flags formatted as bar-separated-values by @KodrAus in https://github.com/bitflags/bitflags/pull/297
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @rusty-snake made their first contribution in https://github.com/bitflags/bitflags/pull/291
|
||||||
|
* @fintelia made their first contribution in https://github.com/bitflags/bitflags/pull/294
|
||||||
|
* @nim65s made their first contribution in https://github.com/bitflags/bitflags/pull/296
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/2.0.0-rc.1...2.0.0-rc.2
|
||||||
|
|
||||||
|
# 2.0.0-rc.1
|
||||||
|
|
||||||
|
This is a big release including a few years worth of work on a new `BitFlags` trait, iteration, and better macro organization for future extensibility.
|
||||||
|
|
||||||
|
## What's Changed
|
||||||
|
* Fix a typo and call out MSRV bump by @KodrAus in https://github.com/bitflags/bitflags/pull/259
|
||||||
|
* BitFlags trait by @arturoc in https://github.com/bitflags/bitflags/pull/220
|
||||||
|
* Add a hidden trait to discourage manual impls of BitFlags by @KodrAus in https://github.com/bitflags/bitflags/pull/261
|
||||||
|
* Sanitize `Ok` by @konsumlamm in https://github.com/bitflags/bitflags/pull/266
|
||||||
|
* Fix bug in `Debug` implementation by @konsumlamm in https://github.com/bitflags/bitflags/pull/268
|
||||||
|
* Fix a typo in the generated documentation by @wackbyte in https://github.com/bitflags/bitflags/pull/271
|
||||||
|
* Use SPDX license format by @atouchet in https://github.com/bitflags/bitflags/pull/272
|
||||||
|
* serde tests fail in CI by @arturoc in https://github.com/bitflags/bitflags/pull/277
|
||||||
|
* Fix beta test output by @KodrAus in https://github.com/bitflags/bitflags/pull/279
|
||||||
|
* Add example to the README.md file by @tiaanl in https://github.com/bitflags/bitflags/pull/270
|
||||||
|
* Iterator over all the enabled options by @arturoc in https://github.com/bitflags/bitflags/pull/278
|
||||||
|
* from_bits_(truncate) fail with composite flags by @arturoc in https://github.com/bitflags/bitflags/pull/276
|
||||||
|
* Add more platform coverage to CI by @KodrAus in https://github.com/bitflags/bitflags/pull/280
|
||||||
|
* rework the way cfgs are handled by @KodrAus in https://github.com/bitflags/bitflags/pull/281
|
||||||
|
* Split generated code into two types by @KodrAus in https://github.com/bitflags/bitflags/pull/282
|
||||||
|
* expose bitflags iters using nameable types by @KodrAus in https://github.com/bitflags/bitflags/pull/286
|
||||||
|
* Support creating flags from their names by @KodrAus in https://github.com/bitflags/bitflags/pull/287
|
||||||
|
* Update README.md by @KodrAus in https://github.com/bitflags/bitflags/pull/288
|
||||||
|
|
||||||
|
## New Contributors
|
||||||
|
* @wackbyte made their first contribution in https://github.com/bitflags/bitflags/pull/271
|
||||||
|
* @atouchet made their first contribution in https://github.com/bitflags/bitflags/pull/272
|
||||||
|
* @tiaanl made their first contribution in https://github.com/bitflags/bitflags/pull/270
|
||||||
|
|
||||||
|
**Full Changelog**: https://github.com/bitflags/bitflags/compare/1.3.2...2.0.0-rc.1
|
||||||
|
|
||||||
# 1.3.2
|
# 1.3.2
|
||||||
|
|
||||||
- Allow `non_snake_case` in generated flags types ([#256])
|
- Allow `non_snake_case` in generated flags types ([#256])
|
||||||
|
|
||||||
[#252]: https://github.com/bitflags/bitflags/pull/256
|
[#256]: https://github.com/bitflags/bitflags/pull/256
|
||||||
|
|
||||||
# 1.3.1
|
# 1.3.1
|
||||||
|
|
||||||
@ -12,6 +239,8 @@
|
|||||||
|
|
||||||
# 1.3.0 (yanked)
|
# 1.3.0 (yanked)
|
||||||
|
|
||||||
|
**This release bumps the Minimum Supported Rust Version to `1.46.0`**
|
||||||
|
|
||||||
- Add `#[repr(transparent)]` ([#187])
|
- Add `#[repr(transparent)]` ([#187])
|
||||||
|
|
||||||
- End `empty` doc comment with full stop ([#202])
|
- End `empty` doc comment with full stop ([#202])
|
||||||
|
9
third_party/rust/bitflags/CONTRIBUTING.md
vendored
Normal file
9
third_party/rust/bitflags/CONTRIBUTING.md
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Updating compile-fail test outputs
|
||||||
|
|
||||||
|
`bitflags` uses the `trybuild` crate to integration test its macros. Since Rust error messages change frequently enough that `nightly` builds produce spurious failures, we only check the compiler output in `beta` builds. If you run:
|
||||||
|
|
||||||
|
```
|
||||||
|
TRYBUILD=overwrite cargo +beta test --all
|
||||||
|
```
|
||||||
|
|
||||||
|
it will run the tests and update the `trybuild` output files.
|
265
third_party/rust/bitflags/Cargo.lock
generated
vendored
Normal file
265
third_party/rust/bitflags/Cargo.lock
generated
vendored
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "arbitrary"
|
||||||
|
version = "1.3.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e2d098ff73c1ca148721f37baad5ea6a465a13f9573aba8641fbbbae8164a54e"
|
||||||
|
dependencies = [
|
||||||
|
"derive_arbitrary",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "basic-toml"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7bfc506e7a2370ec239e1d072507b2a80c833083699d3c6fa176fbb4de8448c6"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.4.0"
|
||||||
|
dependencies = [
|
||||||
|
"arbitrary",
|
||||||
|
"bytemuck",
|
||||||
|
"compiler_builtins",
|
||||||
|
"rustc-std-workspace-core",
|
||||||
|
"rustversion",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"serde_test",
|
||||||
|
"trybuild",
|
||||||
|
"zerocopy",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck"
|
||||||
|
version = "1.13.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea"
|
||||||
|
dependencies = [
|
||||||
|
"bytemuck_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bytemuck_derive"
|
||||||
|
version = "1.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "byteorder"
|
||||||
|
version = "1.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "compiler_builtins"
|
||||||
|
version = "0.1.100"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d6c0f24437059853f0fa64afc51f338f93647a3de4cf3358ba1bb4171a199775"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_arbitrary"
|
||||||
|
version = "1.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53e0efad4403bfc52dc201159c4b842a246a14b98c64b55dfd0f2d89729dfeb8"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "glob"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell"
|
||||||
|
version = "1.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.66"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-std-workspace-core"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1956f5517128a2b6f23ab2dadf1a976f4f5b27962e7724c2bf3d45e539ec098c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustversion"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.183"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.183"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "aafe972d60b0b9bee71a91b92fee2d4fb3c9d7e8f6b179aa99f27203d99a4816"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.104"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "076066c5f1078eac5b722a31827a8832fe108bed65dfa75e233c89f8206e976c"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_test"
|
||||||
|
version = "1.0.176"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a2f49ace1498612d14f7e0b8245519584db8299541dfe31a06374a828d620ab"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.28"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "termcolor"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6"
|
||||||
|
dependencies = [
|
||||||
|
"winapi-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "trybuild"
|
||||||
|
version = "1.0.82"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a84e0202ea606ba5ebee8507ab2bfbe89b98551ed9b8f0be198109275cff284b"
|
||||||
|
dependencies = [
|
||||||
|
"basic-toml",
|
||||||
|
"glob",
|
||||||
|
"once_cell",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
|
"termcolor",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c"
|
||||||
|
|
||||||
|
[[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-util"
|
||||||
|
version = "0.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
|
dependencies = [
|
||||||
|
"winapi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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 = "zerocopy"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f3b9c234616391070b0b173963ebc65a9195068e7ed3731c6edac2ec45ebe106"
|
||||||
|
dependencies = [
|
||||||
|
"byteorder",
|
||||||
|
"zerocopy-derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "zerocopy-derive"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f7f3a471f98d0a61c34322fbbfd10c384b07687f680d4119813713f72308d91"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
73
third_party/rust/bitflags/Cargo.toml
vendored
73
third_party/rust/bitflags/Cargo.toml
vendored
@ -3,29 +3,49 @@
|
|||||||
# When uploading crates to the registry Cargo will automatically
|
# When uploading crates to the registry Cargo will automatically
|
||||||
# "normalize" Cargo.toml files for maximal compatibility
|
# "normalize" Cargo.toml files for maximal compatibility
|
||||||
# with all versions of Cargo and also rewrite `path` dependencies
|
# with all versions of Cargo and also rewrite `path` dependencies
|
||||||
# to registry (e.g., crates.io) dependencies
|
# to registry (e.g., crates.io) dependencies.
|
||||||
#
|
#
|
||||||
# If you believe there's an error in this file please file an
|
# If you are reading this file be aware that the original Cargo.toml
|
||||||
# issue against the rust-lang/cargo repository. If you're
|
# will likely look very different (and much more reasonable).
|
||||||
# editing this file be aware that the upstream Cargo.toml
|
# See Cargo.toml.orig for the original contents.
|
||||||
# will likely look very different (and much more reasonable)
|
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
|
rust-version = "1.56.0"
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "1.3.2"
|
version = "2.4.0"
|
||||||
authors = ["The Rust Project Developers"]
|
authors = ["The Rust Project Developers"]
|
||||||
exclude = ["bors.toml"]
|
exclude = [
|
||||||
description = "A macro to generate structures which behave like bitflags.\n"
|
"tests",
|
||||||
|
".github",
|
||||||
|
]
|
||||||
|
description = """
|
||||||
|
A macro to generate structures which behave like bitflags.
|
||||||
|
"""
|
||||||
homepage = "https://github.com/bitflags/bitflags"
|
homepage = "https://github.com/bitflags/bitflags"
|
||||||
documentation = "https://docs.rs/bitflags"
|
documentation = "https://docs.rs/bitflags"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
keywords = ["bit", "bitmask", "bitflags", "flags"]
|
keywords = [
|
||||||
|
"bit",
|
||||||
|
"bitmask",
|
||||||
|
"bitflags",
|
||||||
|
"flags",
|
||||||
|
]
|
||||||
categories = ["no-std"]
|
categories = ["no-std"]
|
||||||
license = "MIT/Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
repository = "https://github.com/bitflags/bitflags"
|
repository = "https://github.com/bitflags/bitflags"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["example_generated"]
|
features = ["example_generated"]
|
||||||
|
|
||||||
|
[dependencies.arbitrary]
|
||||||
|
version = "1.0"
|
||||||
|
optional = true
|
||||||
|
|
||||||
|
[dependencies.bytemuck]
|
||||||
|
version = "1.0"
|
||||||
|
optional = true
|
||||||
|
|
||||||
[dependencies.compiler_builtins]
|
[dependencies.compiler_builtins]
|
||||||
version = "0.1.2"
|
version = "0.1.2"
|
||||||
optional = true
|
optional = true
|
||||||
@ -34,10 +54,21 @@ optional = true
|
|||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
optional = true
|
optional = true
|
||||||
package = "rustc-std-workspace-core"
|
package = "rustc-std-workspace-core"
|
||||||
[dev-dependencies.rustversion]
|
|
||||||
version = "1.0"
|
|
||||||
|
|
||||||
[dev-dependencies.serde]
|
[dependencies.serde]
|
||||||
|
version = "1.0"
|
||||||
|
optional = true
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dev-dependencies.arbitrary]
|
||||||
|
version = "1.0"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
|
[dev-dependencies.bytemuck]
|
||||||
|
version = "1.0"
|
||||||
|
features = ["derive"]
|
||||||
|
|
||||||
|
[dev-dependencies.rustversion]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
[dev-dependencies.serde_derive]
|
[dev-dependencies.serde_derive]
|
||||||
@ -46,13 +77,19 @@ version = "1.0"
|
|||||||
[dev-dependencies.serde_json]
|
[dev-dependencies.serde_json]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
|
[dev-dependencies.serde_test]
|
||||||
|
version = "1.0"
|
||||||
|
|
||||||
[dev-dependencies.trybuild]
|
[dev-dependencies.trybuild]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
[dev-dependencies.walkdir]
|
[dev-dependencies.zerocopy]
|
||||||
version = "2.3"
|
version = "0.6"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
|
||||||
example_generated = []
|
example_generated = []
|
||||||
rustc-dep-of-std = ["core", "compiler_builtins"]
|
rustc-dep-of-std = [
|
||||||
|
"core",
|
||||||
|
"compiler_builtins",
|
||||||
|
]
|
||||||
|
std = []
|
||||||
|
47
third_party/rust/bitflags/README.md
vendored
47
third_party/rust/bitflags/README.md
vendored
@ -2,14 +2,24 @@ bitflags
|
|||||||
========
|
========
|
||||||
|
|
||||||
[![Rust](https://github.com/bitflags/bitflags/workflows/Rust/badge.svg)](https://github.com/bitflags/bitflags/actions)
|
[![Rust](https://github.com/bitflags/bitflags/workflows/Rust/badge.svg)](https://github.com/bitflags/bitflags/actions)
|
||||||
[![Join the chat at https://gitter.im/bitflags/Lobby](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bitflags/Lobby?utm_source=badge&utm_medium=badge&utm_content=badge)
|
|
||||||
[![Latest version](https://img.shields.io/crates/v/bitflags.svg)](https://crates.io/crates/bitflags)
|
[![Latest version](https://img.shields.io/crates/v/bitflags.svg)](https://crates.io/crates/bitflags)
|
||||||
[![Documentation](https://docs.rs/bitflags/badge.svg)](https://docs.rs/bitflags)
|
[![Documentation](https://docs.rs/bitflags/badge.svg)](https://docs.rs/bitflags)
|
||||||
![License](https://img.shields.io/crates/l/bitflags.svg)
|
![License](https://img.shields.io/crates/l/bitflags.svg)
|
||||||
|
|
||||||
A Rust macro to generate structures which behave like a set of bitflags
|
`bitflags` generates flags enums with well-defined semantics and ergonomic end-user APIs.
|
||||||
|
|
||||||
|
You can use `bitflags` to:
|
||||||
|
|
||||||
|
- provide more user-friendly bindings to C APIs where flags may or may not be fully known in advance.
|
||||||
|
- generate efficient options types with string parsing and formatting support.
|
||||||
|
|
||||||
|
You can't use `bitflags` to:
|
||||||
|
|
||||||
|
- guarantee only bits corresponding to defined flags will ever be set. `bitflags` allows access to the underlying bits type so arbitrary bits may be set.
|
||||||
|
- define bitfields. `bitflags` only generates types where set bits denote the presence of some combination of flags.
|
||||||
|
|
||||||
- [Documentation](https://docs.rs/bitflags)
|
- [Documentation](https://docs.rs/bitflags)
|
||||||
|
- [Specification](https://github.com/bitflags/bitflags/blob/main/spec.md)
|
||||||
- [Release notes](https://github.com/bitflags/bitflags/releases)
|
- [Release notes](https://github.com/bitflags/bitflags/releases)
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -18,7 +28,7 @@ Add this to your `Cargo.toml`:
|
|||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "1.3"
|
bitflags = "2.4.0"
|
||||||
```
|
```
|
||||||
|
|
||||||
and this to your source code:
|
and this to your source code:
|
||||||
@ -27,6 +37,35 @@ and this to your source code:
|
|||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Generate a flags structure:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
// The `bitflags!` macro generates `struct`s that manage a set of flags.
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
struct Flags: u32 {
|
||||||
|
const A = 0b00000001;
|
||||||
|
const B = 0b00000010;
|
||||||
|
const C = 0b00000100;
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let e1 = Flags::A | Flags::C;
|
||||||
|
let e2 = Flags::B | Flags::C;
|
||||||
|
assert_eq!((e1 | e2), Flags::ABC); // union
|
||||||
|
assert_eq!((e1 & e2), Flags::C); // intersection
|
||||||
|
assert_eq!((e1 - e2), Flags::A); // set difference
|
||||||
|
assert_eq!(!e2, Flags::A); // set complement
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Rust Version Support
|
## Rust Version Support
|
||||||
|
|
||||||
The minimum supported Rust version is 1.46 due to use of associated constants and const functions.
|
The minimum supported Rust version is documented in the `Cargo.toml` file.
|
||||||
|
This may be bumped in minor releases as necessary.
|
||||||
|
13
third_party/rust/bitflags/SECURITY.md
vendored
Normal file
13
third_party/rust/bitflags/SECURITY.md
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Security Policy
|
||||||
|
|
||||||
|
## Supported Versions
|
||||||
|
|
||||||
|
Security updates are applied only to the latest release.
|
||||||
|
|
||||||
|
## Reporting a Vulnerability
|
||||||
|
|
||||||
|
If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released.
|
||||||
|
|
||||||
|
Please disclose it at [security advisory](https://github.com/bitflags/bitflags/security/advisories/new).
|
||||||
|
|
||||||
|
This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure.
|
96
third_party/rust/bitflags/benches/parse.rs
vendored
Normal file
96
third_party/rust/bitflags/benches/parse.rs
vendored
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
#![feature(test)]
|
||||||
|
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
use std::{
|
||||||
|
fmt::{self, Display},
|
||||||
|
str::FromStr,
|
||||||
|
};
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
struct Flags10: u32 {
|
||||||
|
const A = 0b0000_0000_0000_0001;
|
||||||
|
const B = 0b0000_0000_0000_0010;
|
||||||
|
const C = 0b0000_0000_0000_0100;
|
||||||
|
const D = 0b0000_0000_0000_1000;
|
||||||
|
const E = 0b0000_0000_0001_0000;
|
||||||
|
const F = 0b0000_0000_0010_0000;
|
||||||
|
const G = 0b0000_0000_0100_0000;
|
||||||
|
const H = 0b0000_0000_1000_0000;
|
||||||
|
const I = 0b0000_0001_0000_0000;
|
||||||
|
const J = 0b0000_0010_0000_0000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for Flags10 {
|
||||||
|
type Err = bitflags::parser::ParseError;
|
||||||
|
|
||||||
|
fn from_str(flags: &str) -> Result<Self, Self::Err> {
|
||||||
|
Ok(Flags10(flags.parse()?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for Flags10 {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
Display::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn format_flags_1_present(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| Flags10::J.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn format_flags_5_present(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| (Flags10::F | Flags10::G | Flags10::H | Flags10::I | Flags10::J).to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn format_flags_10_present(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
(Flags10::A
|
||||||
|
| Flags10::B
|
||||||
|
| Flags10::C
|
||||||
|
| Flags10::D
|
||||||
|
| Flags10::E
|
||||||
|
| Flags10::F
|
||||||
|
| Flags10::G
|
||||||
|
| Flags10::H
|
||||||
|
| Flags10::I
|
||||||
|
| Flags10::J)
|
||||||
|
.to_string()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn parse_flags_1_10(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
let flags: Flags10 = "J".parse().unwrap();
|
||||||
|
flags
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn parse_flags_5_10(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
let flags: Flags10 = "F | G | H | I | J".parse().unwrap();
|
||||||
|
flags
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn parse_flags_10_10(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
let flags: Flags10 = "A | B | C | D | E | F | G | H | I | J".parse().unwrap();
|
||||||
|
flags
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn parse_flags_1_10_hex(b: &mut test::Bencher) {
|
||||||
|
b.iter(|| {
|
||||||
|
let flags: Flags10 = "0xFF".parse().unwrap();
|
||||||
|
flags
|
||||||
|
})
|
||||||
|
}
|
97
third_party/rust/bitflags/examples/custom_bits_type.rs
vendored
Normal file
97
third_party/rust/bitflags/examples/custom_bits_type.rs
vendored
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
use std::ops::{BitAnd, BitOr, BitXor, Not};
|
||||||
|
|
||||||
|
use bitflags::{Bits, Flag, Flags};
|
||||||
|
|
||||||
|
// Define a custom container that can be used in flags types
|
||||||
|
// Note custom bits types can't be used in `bitflags!`
|
||||||
|
// without making the trait impls `const`. This is currently
|
||||||
|
// unstable
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct CustomBits([bool; 3]);
|
||||||
|
|
||||||
|
impl Bits for CustomBits {
|
||||||
|
const EMPTY: Self = CustomBits([false; 3]);
|
||||||
|
|
||||||
|
const ALL: Self = CustomBits([true; 3]);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PartialEq for CustomBits {
|
||||||
|
fn eq(&self, other: &Self) -> bool {
|
||||||
|
self.0 == other.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitAnd for CustomBits {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn bitand(self, other: Self) -> Self {
|
||||||
|
CustomBits([
|
||||||
|
self.0[0] & other.0[0],
|
||||||
|
self.0[1] & other.0[1],
|
||||||
|
self.0[2] & other.0[2],
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitOr for CustomBits {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn bitor(self, other: Self) -> Self {
|
||||||
|
CustomBits([
|
||||||
|
self.0[0] | other.0[0],
|
||||||
|
self.0[1] | other.0[1],
|
||||||
|
self.0[2] | other.0[2],
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BitXor for CustomBits {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn bitxor(self, other: Self) -> Self {
|
||||||
|
CustomBits([
|
||||||
|
self.0[0] & other.0[0],
|
||||||
|
self.0[1] & other.0[1],
|
||||||
|
self.0[2] & other.0[2],
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Not for CustomBits {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
fn not(self) -> Self {
|
||||||
|
CustomBits([!self.0[0], !self.0[1], !self.0[2]])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
pub struct CustomFlags(CustomBits);
|
||||||
|
|
||||||
|
impl CustomFlags {
|
||||||
|
pub const A: Self = CustomFlags(CustomBits([true, false, false]));
|
||||||
|
pub const B: Self = CustomFlags(CustomBits([false, true, false]));
|
||||||
|
pub const C: Self = CustomFlags(CustomBits([false, false, true]));
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Flags for CustomFlags {
|
||||||
|
const FLAGS: &'static [Flag<Self>] = &[
|
||||||
|
Flag::new("A", Self::A),
|
||||||
|
Flag::new("B", Self::B),
|
||||||
|
Flag::new("C", Self::C),
|
||||||
|
];
|
||||||
|
|
||||||
|
type Bits = CustomBits;
|
||||||
|
|
||||||
|
fn bits(&self) -> Self::Bits {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_retain(bits: Self::Bits) -> Self {
|
||||||
|
CustomFlags(bits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!("{:?}", CustomFlags::A.union(CustomFlags::C));
|
||||||
|
}
|
23
third_party/rust/bitflags/examples/custom_derive.rs
vendored
Normal file
23
third_party/rust/bitflags/examples/custom_derive.rs
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//! An example of implementing the `BitFlags` trait manually for a flags type.
|
||||||
|
|
||||||
|
use std::str;
|
||||||
|
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
// Define a flags type outside of the `bitflags` macro as a newtype
|
||||||
|
// It can accept custom derives for libaries `bitflags` doesn't support natively
|
||||||
|
#[derive(zerocopy::AsBytes, zerocopy::FromBytes)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct ManualFlags(u32);
|
||||||
|
|
||||||
|
// Next: use `impl Flags` instead of `struct Flags`
|
||||||
|
bitflags! {
|
||||||
|
impl ManualFlags: u32 {
|
||||||
|
const A = 0b00000001;
|
||||||
|
const B = 0b00000010;
|
||||||
|
const C = 0b00000100;
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
49
third_party/rust/bitflags/examples/fmt.rs
vendored
Normal file
49
third_party/rust/bitflags/examples/fmt.rs
vendored
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
//! An example of implementing Rust's standard formatting and parsing traits for flags types.
|
||||||
|
|
||||||
|
use core::{fmt, str};
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
// You can `#[derive]` the `Debug` trait, but implementing it manually
|
||||||
|
// can produce output like `A | B` instead of `Flags(A | B)`.
|
||||||
|
// #[derive(Debug)]
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
pub struct Flags: u32 {
|
||||||
|
const A = 1;
|
||||||
|
const B = 2;
|
||||||
|
const C = 4;
|
||||||
|
const D = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Debug for Flags {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
bitflags::parser::to_writer(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Flags {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
bitflags::parser::to_writer(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl str::FromStr for Flags {
|
||||||
|
type Err = bitflags::parser::ParseError;
|
||||||
|
|
||||||
|
fn from_str(flags: &str) -> Result<Self, Self::Err> {
|
||||||
|
bitflags::parser::from_str(flags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> Result<(), bitflags::parser::ParseError> {
|
||||||
|
let flags = Flags::A | Flags::B;
|
||||||
|
|
||||||
|
println!("{}", flags);
|
||||||
|
|
||||||
|
let formatted = flags.to_string();
|
||||||
|
let parsed: Flags = formatted.parse()?;
|
||||||
|
|
||||||
|
assert_eq!(flags, parsed);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
61
third_party/rust/bitflags/examples/macro_free.rs
vendored
Normal file
61
third_party/rust/bitflags/examples/macro_free.rs
vendored
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
//! An example of implementing the `BitFlags` trait manually for a flags type.
|
||||||
|
//!
|
||||||
|
//! This example doesn't use any macros.
|
||||||
|
|
||||||
|
use std::{fmt, str};
|
||||||
|
|
||||||
|
use bitflags::{Flag, Flags};
|
||||||
|
|
||||||
|
// First: Define your flags type. It just needs to be `Sized + 'static`.
|
||||||
|
pub struct ManualFlags(u32);
|
||||||
|
|
||||||
|
// Not required: Define some constants for valid flags
|
||||||
|
impl ManualFlags {
|
||||||
|
pub const A: ManualFlags = ManualFlags(0b00000001);
|
||||||
|
pub const B: ManualFlags = ManualFlags(0b00000010);
|
||||||
|
pub const C: ManualFlags = ManualFlags(0b00000100);
|
||||||
|
pub const ABC: ManualFlags = ManualFlags(0b00000111);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Next: Implement the `BitFlags` trait, specifying your set of valid flags
|
||||||
|
// and iterators
|
||||||
|
impl Flags for ManualFlags {
|
||||||
|
const FLAGS: &'static [Flag<Self>] = &[
|
||||||
|
Flag::new("A", Self::A),
|
||||||
|
Flag::new("B", Self::B),
|
||||||
|
Flag::new("C", Self::C),
|
||||||
|
];
|
||||||
|
|
||||||
|
type Bits = u32;
|
||||||
|
|
||||||
|
fn bits(&self) -> u32 {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_retain(bits: u32) -> Self {
|
||||||
|
Self(bits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not required: Add parsing support
|
||||||
|
impl str::FromStr for ManualFlags {
|
||||||
|
type Err = bitflags::parser::ParseError;
|
||||||
|
|
||||||
|
fn from_str(input: &str) -> Result<Self, Self::Err> {
|
||||||
|
bitflags::parser::from_str(input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not required: Add formatting support
|
||||||
|
impl fmt::Display for ManualFlags {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
bitflags::parser::to_writer(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
println!(
|
||||||
|
"{}",
|
||||||
|
ManualFlags::A.union(ManualFlags::B).union(ManualFlags::C)
|
||||||
|
);
|
||||||
|
}
|
36
third_party/rust/bitflags/examples/serde.rs
vendored
Normal file
36
third_party/rust/bitflags/examples/serde.rs
vendored
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
//! An example of implementing `serde::Serialize` and `serde::Deserialize`.
|
||||||
|
//! The `#[serde(transparent)]` attribute is recommended to serialize directly
|
||||||
|
//! to the underlying bits type without wrapping it in a `serde` newtype.
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
fn main() {
|
||||||
|
use serde_derive::*;
|
||||||
|
|
||||||
|
bitflags::bitflags! {
|
||||||
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
pub struct Flags: u32 {
|
||||||
|
const A = 1;
|
||||||
|
const B = 2;
|
||||||
|
const C = 4;
|
||||||
|
const D = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let flags = Flags::A | Flags::B;
|
||||||
|
|
||||||
|
let serialized = serde_json::to_string(&flags).unwrap();
|
||||||
|
|
||||||
|
println!("{:?} -> {}", flags, serialized);
|
||||||
|
|
||||||
|
assert_eq!(serialized, r#""A | B""#);
|
||||||
|
|
||||||
|
let deserialized: Flags = serde_json::from_str(&serialized).unwrap();
|
||||||
|
|
||||||
|
println!("{} -> {:?}", serialized, flags);
|
||||||
|
|
||||||
|
assert_eq!(deserialized, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
fn main() {}
|
552
third_party/rust/bitflags/spec.md
vendored
Normal file
552
third_party/rust/bitflags/spec.md
vendored
Normal file
@ -0,0 +1,552 @@
|
|||||||
|
# Bitflags
|
||||||
|
|
||||||
|
`bitflags` generates flags enums with well-defined semantics and ergonomic end-user APIs.
|
||||||
|
|
||||||
|
You can use `bitflags` to:
|
||||||
|
|
||||||
|
- provide more user-friendly bindings to C APIs where flags may or may not be fully known in advance.
|
||||||
|
- generate efficient options types with string parsing and formatting support.
|
||||||
|
|
||||||
|
You can't use `bitflags` to:
|
||||||
|
|
||||||
|
- guarantee only bits corresponding to defined flags will ever be set. `bitflags` allows access to the underlying bits type so arbitrary bits may be set.
|
||||||
|
- define bitfields. `bitflags` only generates types where set bits denote the presence of some combination of flags.
|
||||||
|
|
||||||
|
## Definitions
|
||||||
|
|
||||||
|
This section formally defines the terminology and semantics of `bitflags`. It's organized so more fundamental concepts are introduced before those that build on them. It may be helpful to start from the bottom of the section and refer back up to concepts defined earlier.
|
||||||
|
|
||||||
|
Examples use `bitflags` syntax with `u8` as the bits type.
|
||||||
|
|
||||||
|
### Bits type
|
||||||
|
|
||||||
|
A type that defines a fixed number of bits at specific locations.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Bits types are typically fixed-width unsigned integers. For example, `u8` is a bits type that defines 8 bits; bit-0 through bit-7.
|
||||||
|
|
||||||
|
### Bits value
|
||||||
|
|
||||||
|
An instance of a bits type where each bit may be set (`1`) or unset (`0`).
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Some examples of bits values for the bits type `u8` are:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0000
|
||||||
|
0b1111_1111
|
||||||
|
0b1010_0101
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Equality
|
||||||
|
|
||||||
|
Two bits values are equal if their bits are in the same configuration; set bits in one are set in the other, and unset bits in one are unset in the other.
|
||||||
|
|
||||||
|
#### Operations
|
||||||
|
|
||||||
|
Bits values define the bitwise operators and (`&`), or (`|`), exclusive-or (`^`), and negation (`!`) that apply to each of their bits.
|
||||||
|
|
||||||
|
### Flag
|
||||||
|
|
||||||
|
A set of bits in a bits type that may have a unique name.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Bits are not required to be exclusive to a flag. Bits are not required to be contiguous.
|
||||||
|
|
||||||
|
The following is a flag for `u8` with the name `A` that includes bit-0:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
```
|
||||||
|
|
||||||
|
The following is a flag for `u8` with the name `B` that includes bit-0, and bit-5:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const B = 0b0010_0001;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Named flag
|
||||||
|
|
||||||
|
A flag with a name.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following is a named flag, where the name is `A`:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Unnamed flag
|
||||||
|
|
||||||
|
A flag without a name.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following is an unnamed flag:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const _ = 0b0000_0001;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Zero-bit flag
|
||||||
|
|
||||||
|
A flag with a set of zero bits.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following is a zero-bit flag:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const ZERO = 0b0000_0000;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Single-bit flag
|
||||||
|
|
||||||
|
A flag with a set of one bit.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are single-bit flags:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Multi-bit flag
|
||||||
|
|
||||||
|
A flag with a set of more than one bit.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are multi-bit flags:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
const A = 0b0000_0011;
|
||||||
|
const B = 0b1111_1111;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Flags type
|
||||||
|
|
||||||
|
A set of defined flags over a specific bits type.
|
||||||
|
|
||||||
|
#### Known bit
|
||||||
|
|
||||||
|
A bit in any defined flag.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
In the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
const C = 0b0000_0100;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
the known bits are:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0111
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Unknown bit
|
||||||
|
|
||||||
|
A bit not in any defined flag.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
In the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
const C = 0b0000_0100;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
the unknown bits are:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b1111_1000
|
||||||
|
```
|
||||||
|
|
||||||
|
### Flags value
|
||||||
|
|
||||||
|
An instance of a flags type using its specific bits value for storage.
|
||||||
|
|
||||||
|
The flags value of a flag is one where each of its bits is set, and all others are unset.
|
||||||
|
|
||||||
|
#### Contains
|
||||||
|
|
||||||
|
Whether all set bits in a source flags value are also set in a target flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0011
|
||||||
|
```
|
||||||
|
|
||||||
|
the following flags values are contained:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0000
|
||||||
|
0b0000_0010
|
||||||
|
0b0000_0001
|
||||||
|
0b0000_0011
|
||||||
|
```
|
||||||
|
|
||||||
|
but the following flags values are not contained:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_1000
|
||||||
|
0b0000_0110
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Intersects
|
||||||
|
|
||||||
|
Whether any set bits in a source flags value are also set in a target flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0011
|
||||||
|
```
|
||||||
|
|
||||||
|
the following flags intersect:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0010
|
||||||
|
0b0000_0001
|
||||||
|
0b1111_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
but the following flags values do not intersect:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0000
|
||||||
|
0b1111_0000
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Empty
|
||||||
|
|
||||||
|
Whether all bits in a flags value are unset.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following flags value is empty:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0000
|
||||||
|
```
|
||||||
|
|
||||||
|
The following flags values are not empty:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001
|
||||||
|
0b0110_0000
|
||||||
|
```
|
||||||
|
|
||||||
|
#### All
|
||||||
|
|
||||||
|
Whether all defined flags are contained in a flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given a flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
the following flags values all satisfy all:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0011
|
||||||
|
0b1000_0011
|
||||||
|
0b1111_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
### Operations
|
||||||
|
|
||||||
|
Examples in this section all use the given flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
const C = 0b0000_1100;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Truncate
|
||||||
|
|
||||||
|
Unset all unknown bits in a flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b1111_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
the result of truncation will be:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Truncating doesn't guarantee that a non-empty result will contain any defined flags. Given the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0101;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and the following flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_1110;
|
||||||
|
```
|
||||||
|
|
||||||
|
The result of truncation will be:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0100;
|
||||||
|
```
|
||||||
|
|
||||||
|
which intersects the flag `A`, but doesn't contain it.
|
||||||
|
|
||||||
|
This behavior is possible even when only operating with flags values containing defined flags. Given the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0101;
|
||||||
|
const B = 0b0000_0001;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The result of `A ^ B` is `0b0000_0100`, which also doesn't contain any defined flag.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
If all known bits are in the set of at least one defined single-bit flag, then all operations that produce non-empty results will always contain defined flags.
|
||||||
|
|
||||||
|
#### Union
|
||||||
|
|
||||||
|
The bitwise or (`|`) of the bits in two flags values.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are examples of the result of unioning flags values:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001 | 0b0000_0010 = 0b0000_0011
|
||||||
|
0b0000_0000 | 0b1111_1111 = 0b1111_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Intersection
|
||||||
|
|
||||||
|
The bitwise and (`&`) of the bits in two flags values.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are examples of the result of intersecting flags values:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001 & 0b0000_0010 = 0b0000_0000
|
||||||
|
0b1111_1100 & 0b1111_0111 = 0b1111_0100
|
||||||
|
0b1111_1111 & 0b1111_1111 = 0b1111_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Symmetric difference
|
||||||
|
|
||||||
|
The bitwise exclusive-or (`^`) of the bits in two flags values.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are examples of the symmetric difference between two flags values:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001 ^ 0b0000_0010 = 0b0000_0011
|
||||||
|
0b0000_1111 ^ 0b0000_0011 = 0b0000_1100
|
||||||
|
0b1100_0000 ^ 0b0011_0000 = 0b1111_0000
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Complement
|
||||||
|
|
||||||
|
The bitwise negation (`!`) of the bits in a flags value, truncating the result.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are examples of the complement of a flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
!0b0000_0000 = 0b0000_1111
|
||||||
|
!0b0000_1111 = 0b0000_0000
|
||||||
|
!0b1111_1000 = 0b0000_0111
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Difference
|
||||||
|
|
||||||
|
The bitwise union (`|`) of the bits in one flags value and the bitwise negation (`!`) of the bits in another.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
This operation is not equivalent to the intersection of one flags value with the complement of another (`&!`).
|
||||||
|
The former will truncate the result, where difference will not.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
The following are examples of the difference between two flags values:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001 & !0b0000_0010 = 0b0000_0001
|
||||||
|
0b0000_1101 & !0b0000_0011 = 0b0000_1100
|
||||||
|
0b1111_1111 & !0b0000_0001 = 0b1111_1110
|
||||||
|
```
|
||||||
|
|
||||||
|
### Iteration
|
||||||
|
|
||||||
|
Yield the bits of a source flags value in a set of contained flags values.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
To be most useful, each yielded flags value should set exactly the bits of a defined flag contained in the source. Any known bits that aren't in the set of any contained flag should be yielded together as a final flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
const AB = 0b0000_0011;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and the following flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_1111
|
||||||
|
```
|
||||||
|
|
||||||
|
When iterated it may yield a flags value for `A` and `B`, then a final flag with the unknown bits:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001
|
||||||
|
0b0000_0010
|
||||||
|
0b0000_1100
|
||||||
|
```
|
||||||
|
|
||||||
|
It may also yield a flags value for `AB`, then a final flag with the unknown bits:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0011
|
||||||
|
0b0000_1100
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0011;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
and the following flags value:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0001
|
||||||
|
```
|
||||||
|
|
||||||
|
When iterated it will still yield a flags value for the known bit `0b0000_0001` even though it doesn't contain a flag.
|
||||||
|
|
||||||
|
### Formatting
|
||||||
|
|
||||||
|
Format and parse a flags value as text using the following grammar:
|
||||||
|
|
||||||
|
- _Flags:_ (_Whitespace_ _Flag_ _Whitespace_)`|`*
|
||||||
|
- _Flag:_ _Name_ | _Hex Number_
|
||||||
|
- _Name:_ The name of any defined flag
|
||||||
|
- _Hex Number_: `0x`([0-9a-fA-F])*
|
||||||
|
- _Whitespace_: (\s)*
|
||||||
|
|
||||||
|
Flags values can be formatted as _Flags_ by iterating over them, formatting each yielded flags value as a _Flag_. Any yielded flags value that sets exactly the bits of a defined flag with a name should be formatted as a _Name_. Otherwise it must be formatted as a _Hex Number_.
|
||||||
|
|
||||||
|
Formatting and parsing supports three modes:
|
||||||
|
|
||||||
|
- **Retain**: Formatting and parsing roundtrips exactly the bits of the source flags value. This is the default behavior.
|
||||||
|
- **Truncate**: Flags values are truncated before formatting, and truncated after parsing.
|
||||||
|
- **Strict**: A _Flag_ may only be formatted and parsed as a _Name_. _Hex numbers_ are not allowed. A consequence of this is that unknown bits and any bits that aren't in a contained named flag will be ignored. This is recommended for flags values serialized across API boundaries, like web services.
|
||||||
|
|
||||||
|
Text that is empty or whitespace is an empty flags value.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Given the following flags type:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
struct Flags {
|
||||||
|
const A = 0b0000_0001;
|
||||||
|
const B = 0b0000_0010;
|
||||||
|
const AB = 0b0000_0011;
|
||||||
|
const C = 0b0000_1100;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The following are examples of how flags values can be formatted using any mode:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b0000_0000 = ""
|
||||||
|
0b0000_0001 = "A"
|
||||||
|
0b0000_0010 = "B"
|
||||||
|
0b0000_0011 = "A | B"
|
||||||
|
0b0000_0011 = "AB"
|
||||||
|
0b0000_1111 = "A | B | C"
|
||||||
|
```
|
||||||
|
|
||||||
|
Truncate mode will unset any unknown bits:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b1000_0000 = ""
|
||||||
|
0b1111_1111 = "A | B | C"
|
||||||
|
0b0000_1000 = "0x8"
|
||||||
|
```
|
||||||
|
|
||||||
|
Retain mode will include any unknown bits as a final _Flag_:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b1000_0000 = "0x80"
|
||||||
|
0b1111_1111 = "A | B | C | 0xf0"
|
||||||
|
0b0000_1000 = "0x8"
|
||||||
|
```
|
||||||
|
|
||||||
|
Strict mode will unset any unknown bits, as well as bits not contained in any defined named flags:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
0b1000_0000 = ""
|
||||||
|
0b1111_1111 = "A | B | C"
|
||||||
|
0b0000_1000 = ""
|
||||||
|
```
|
@ -1,14 +1,65 @@
|
|||||||
//! This module shows an example of code generated by the macro. **IT MUST NOT BE USED OUTSIDE THIS
|
//! This module shows an example of code generated by the macro. **IT MUST NOT BE USED OUTSIDE THIS
|
||||||
//! CRATE**.
|
//! CRATE**.
|
||||||
|
//!
|
||||||
|
//! Usually, when you call the `bitflags!` macro, only the `Flags` type would be visible. In this
|
||||||
|
//! example, the `Field0`, `Iter`, and `IterRaw` types are also exposed so that you can explore
|
||||||
|
//! their APIs. The `Field0` type can be accessed as `self.0` on an instance of `Flags`.
|
||||||
|
|
||||||
bitflags! {
|
__declare_public_bitflags! {
|
||||||
/// This is the same `Flags` struct defined in the [crate level example](../index.html#example).
|
/// This is the same `Flags` struct defined in the [crate level example](../index.html#example).
|
||||||
/// Note that this struct is just for documentation purposes only, it must not be used outside
|
/// Note that this struct is just for documentation purposes only, it must not be used outside
|
||||||
/// this crate.
|
/// this crate.
|
||||||
pub struct Flags: u32 {
|
pub struct Flags
|
||||||
|
}
|
||||||
|
|
||||||
|
__declare_internal_bitflags! {
|
||||||
|
pub struct Field0: u32
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_internal_bitflags! {
|
||||||
|
Field0: u32, Flags {
|
||||||
|
// Field `A`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000001`.
|
||||||
const A = 0b00000001;
|
const A = 0b00000001;
|
||||||
|
/// Field `B`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000010`.
|
||||||
const B = 0b00000010;
|
const B = 0b00000010;
|
||||||
|
/// Field `C`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000100`.
|
||||||
const C = 0b00000100;
|
const C = 0b00000100;
|
||||||
const ABC = Self::A.bits | Self::B.bits | Self::C.bits;
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_forward! {
|
||||||
|
Flags: u32, Field0
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_ops! {
|
||||||
|
Flags
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_iter! {
|
||||||
|
Flags: u32, Flags
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_consts! {
|
||||||
|
Flags: u32 {
|
||||||
|
/// Field `A`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000001`.
|
||||||
|
const A = 0b00000001;
|
||||||
|
/// Field `B`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000010`.
|
||||||
|
const B = 0b00000010;
|
||||||
|
/// Field `C`.
|
||||||
|
///
|
||||||
|
/// This flag has the value `0b00000100`.
|
||||||
|
const C = 0b00000100;
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
262
third_party/rust/bitflags/src/external.rs
vendored
Normal file
262
third_party/rust/bitflags/src/external.rs
vendored
Normal file
@ -0,0 +1,262 @@
|
|||||||
|
//! Conditional trait implementations for external libraries.
|
||||||
|
|
||||||
|
/*
|
||||||
|
How do I support a new external library?
|
||||||
|
|
||||||
|
Let's say we want to add support for `my_library`.
|
||||||
|
|
||||||
|
First, we create a module under `external`, like `serde` with any specialized code.
|
||||||
|
Ideally, any utilities in here should just work off the `Flags` trait and maybe a
|
||||||
|
few other assumed bounds.
|
||||||
|
|
||||||
|
Next, re-export the library from the `__private` module here.
|
||||||
|
|
||||||
|
Next, define a macro like so:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
macro_rules! __impl_external_bitflags_my_library {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
// Implementation goes here
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(not(feature = "my_library"))]
|
||||||
|
macro_rules! __impl_external_bitflags_my_library {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that the macro is actually defined twice; once for when the `my_library` feature
|
||||||
|
is available, and once for when it's not. This is because the `__impl_external_bitflags_my_library`
|
||||||
|
macro is called in an end-user's library, not in `bitflags`. In an end-user's library we don't
|
||||||
|
know whether or not a particular feature of `bitflags` is enabled, so we unconditionally call
|
||||||
|
the macro, where the body of that macro depends on the feature flag.
|
||||||
|
|
||||||
|
Now, we add our macro call to the `__impl_external_bitflags` macro body:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
__impl_external_bitflags_my_library! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
const $Flag;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
|
||||||
|
pub(crate) mod __private {
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
pub use serde;
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
pub use arbitrary;
|
||||||
|
|
||||||
|
#[cfg(feature = "bytemuck")]
|
||||||
|
pub use bytemuck;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implements traits from external libraries for the internal bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_external_bitflags {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
// Any new library traits impls should be added here
|
||||||
|
// Use `serde` as an example: generate code when the feature is available,
|
||||||
|
// and a no-op when it isn't
|
||||||
|
|
||||||
|
__impl_external_bitflags_serde! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
const $Flag;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_external_bitflags_arbitrary! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
const $Flag;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_external_bitflags_bytemuck! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
const $Flag;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
pub mod serde;
|
||||||
|
|
||||||
|
/// Implement `Serialize` and `Deserialize` for the internal bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "serde")]
|
||||||
|
macro_rules! __impl_external_bitflags_serde {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
impl $crate::__private::serde::Serialize for $InternalBitFlags {
|
||||||
|
fn serialize<S: $crate::__private::serde::Serializer>(
|
||||||
|
&self,
|
||||||
|
serializer: S,
|
||||||
|
) -> $crate::__private::core::result::Result<S::Ok, S::Error> {
|
||||||
|
$crate::serde::serialize(
|
||||||
|
&$PublicBitFlags::from_bits_retain(self.bits()),
|
||||||
|
serializer,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> $crate::__private::serde::Deserialize<'de> for $InternalBitFlags {
|
||||||
|
fn deserialize<D: $crate::__private::serde::Deserializer<'de>>(
|
||||||
|
deserializer: D,
|
||||||
|
) -> $crate::__private::core::result::Result<Self, D::Error> {
|
||||||
|
let flags: $PublicBitFlags = $crate::serde::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
Ok(flags.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(not(feature = "serde"))]
|
||||||
|
macro_rules! __impl_external_bitflags_serde {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
pub mod arbitrary;
|
||||||
|
|
||||||
|
#[cfg(feature = "bytemuck")]
|
||||||
|
mod bytemuck;
|
||||||
|
|
||||||
|
/// Implement `Arbitrary` for the internal bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "arbitrary")]
|
||||||
|
macro_rules! __impl_external_bitflags_arbitrary {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
impl<'a> $crate::__private::arbitrary::Arbitrary<'a> for $InternalBitFlags {
|
||||||
|
fn arbitrary(
|
||||||
|
u: &mut $crate::__private::arbitrary::Unstructured<'a>,
|
||||||
|
) -> $crate::__private::arbitrary::Result<Self> {
|
||||||
|
$crate::arbitrary::arbitrary::<$PublicBitFlags>(u).map(|flags| flags.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(not(feature = "arbitrary"))]
|
||||||
|
macro_rules! __impl_external_bitflags_arbitrary {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement `Pod` and `Zeroable` for the internal bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(feature = "bytemuck")]
|
||||||
|
macro_rules! __impl_external_bitflags_bytemuck {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
// SAFETY: $InternalBitFlags is guaranteed to have the same ABI as $T,
|
||||||
|
// and $T implements Pod
|
||||||
|
unsafe impl $crate::__private::bytemuck::Pod for $InternalBitFlags where
|
||||||
|
$T: $crate::__private::bytemuck::Pod
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// SAFETY: $InternalBitFlags is guaranteed to have the same ABI as $T,
|
||||||
|
// and $T implements Zeroable
|
||||||
|
unsafe impl $crate::__private::bytemuck::Zeroable for $InternalBitFlags where
|
||||||
|
$T: $crate::__private::bytemuck::Zeroable
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[cfg(not(feature = "bytemuck"))]
|
||||||
|
macro_rules! __impl_external_bitflags_bytemuck {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {};
|
||||||
|
}
|
33
third_party/rust/bitflags/src/external/arbitrary.rs
vendored
Normal file
33
third_party/rust/bitflags/src/external/arbitrary.rs
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//! Specialized fuzzing for flags types using `arbitrary`.
|
||||||
|
|
||||||
|
use crate::Flags;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generate some arbitrary flags value with only known bits set.
|
||||||
|
*/
|
||||||
|
pub fn arbitrary<'a, B: Flags>(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<B>
|
||||||
|
where
|
||||||
|
B::Bits: arbitrary::Arbitrary<'a>,
|
||||||
|
{
|
||||||
|
B::from_bits(u.arbitrary()?).ok_or_else(|| arbitrary::Error::IncorrectFormat)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use arbitrary::Arbitrary;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Arbitrary)]
|
||||||
|
struct Color: u32 {
|
||||||
|
const RED = 0x1;
|
||||||
|
const GREEN = 0x2;
|
||||||
|
const BLUE = 0x4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_arbitrary() {
|
||||||
|
let mut unstructured = arbitrary::Unstructured::new(&[0_u8; 256]);
|
||||||
|
let _color = Color::arbitrary(&mut unstructured);
|
||||||
|
}
|
||||||
|
}
|
19
third_party/rust/bitflags/src/external/bytemuck.rs
vendored
Normal file
19
third_party/rust/bitflags/src/external/bytemuck.rs
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use bytemuck::{Pod, Zeroable};
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Pod, Zeroable, Clone, Copy)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
struct Color: u32 {
|
||||||
|
const RED = 0x1;
|
||||||
|
const GREEN = 0x2;
|
||||||
|
const BLUE = 0x4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_bytemuck() {
|
||||||
|
assert_eq!(0x1, bytemuck::cast::<Color, u32>(Color::RED));
|
||||||
|
}
|
||||||
|
}
|
93
third_party/rust/bitflags/src/external/serde.rs
vendored
Normal file
93
third_party/rust/bitflags/src/external/serde.rs
vendored
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
//! Specialized serialization for flags types using `serde`.
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
parser::{self, ParseHex, WriteHex},
|
||||||
|
Flags,
|
||||||
|
};
|
||||||
|
use core::{fmt, str};
|
||||||
|
use serde::{
|
||||||
|
de::{Error, Visitor},
|
||||||
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Serialize a set of flags as a human-readable string or their underlying bits.
|
||||||
|
|
||||||
|
Any unknown bits will be retained.
|
||||||
|
*/
|
||||||
|
pub fn serialize<B: Flags, S: Serializer>(flags: &B, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
|
where
|
||||||
|
B::Bits: WriteHex + Serialize,
|
||||||
|
{
|
||||||
|
// Serialize human-readable flags as a string like `"A | B"`
|
||||||
|
if serializer.is_human_readable() {
|
||||||
|
serializer.collect_str(&parser::AsDisplay(flags))
|
||||||
|
}
|
||||||
|
// Serialize non-human-readable flags directly as the underlying bits
|
||||||
|
else {
|
||||||
|
flags.bits().serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Deserialize a set of flags from a human-readable string or their underlying bits.
|
||||||
|
|
||||||
|
Any unknown bits will be retained.
|
||||||
|
*/
|
||||||
|
pub fn deserialize<'de, B: Flags, D: Deserializer<'de>>(deserializer: D) -> Result<B, D::Error>
|
||||||
|
where
|
||||||
|
B::Bits: ParseHex + Deserialize<'de>,
|
||||||
|
{
|
||||||
|
if deserializer.is_human_readable() {
|
||||||
|
// Deserialize human-readable flags by parsing them from strings like `"A | B"`
|
||||||
|
struct FlagsVisitor<B>(core::marker::PhantomData<B>);
|
||||||
|
|
||||||
|
impl<'de, B: Flags> Visitor<'de> for FlagsVisitor<B>
|
||||||
|
where
|
||||||
|
B::Bits: ParseHex,
|
||||||
|
{
|
||||||
|
type Value = B;
|
||||||
|
|
||||||
|
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
formatter.write_str("a string value of `|` separated flags")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_str<E: Error>(self, flags: &str) -> Result<Self::Value, E> {
|
||||||
|
parser::from_str(flags).map_err(|e| E::custom(e))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deserializer.deserialize_str(FlagsVisitor(Default::default()))
|
||||||
|
} else {
|
||||||
|
// Deserialize non-human-readable flags directly from the underlying bits
|
||||||
|
let bits = B::Bits::deserialize(deserializer)?;
|
||||||
|
|
||||||
|
Ok(B::from_bits_retain(bits))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use serde_test::{assert_tokens, Configure, Token::*};
|
||||||
|
bitflags! {
|
||||||
|
#[derive(serde_derive::Serialize, serde_derive::Deserialize, Debug, PartialEq, Eq)]
|
||||||
|
#[serde(transparent)]
|
||||||
|
struct SerdeFlags: u32 {
|
||||||
|
const A = 1;
|
||||||
|
const B = 2;
|
||||||
|
const C = 4;
|
||||||
|
const D = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_serde_bitflags_default() {
|
||||||
|
assert_tokens(&SerdeFlags::empty().readable(), &[Str("")]);
|
||||||
|
|
||||||
|
assert_tokens(&SerdeFlags::empty().compact(), &[U32(0)]);
|
||||||
|
|
||||||
|
assert_tokens(&(SerdeFlags::A | SerdeFlags::B).readable(), &[Str("A | B")]);
|
||||||
|
|
||||||
|
assert_tokens(&(SerdeFlags::A | SerdeFlags::B).compact(), &[U32(1 | 2)]);
|
||||||
|
}
|
||||||
|
}
|
125
third_party/rust/bitflags/src/internal.rs
vendored
Normal file
125
third_party/rust/bitflags/src/internal.rs
vendored
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
//! Generate the internal `bitflags`-facing flags type.
|
||||||
|
//!
|
||||||
|
//! The code generated here is owned by `bitflags`, but still part of its public API.
|
||||||
|
//! Changes to the types generated here need to be considered like any other public API change.
|
||||||
|
|
||||||
|
/// Declare the `bitflags`-facing bitflags struct.
|
||||||
|
///
|
||||||
|
/// This type is part of the `bitflags` crate's public API, but not part of the user's.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __declare_internal_bitflags {
|
||||||
|
(
|
||||||
|
$vis:vis struct $InternalBitFlags:ident: $T:ty
|
||||||
|
) => {
|
||||||
|
// NOTE: The ABI of this type is _guaranteed_ to be the same as `T`
|
||||||
|
// This is relied on by some external libraries like `bytemuck` to make
|
||||||
|
// its `unsafe` trait impls sound.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
$vis struct $InternalBitFlags($T);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement functions on the private (bitflags-facing) bitflags type.
|
||||||
|
///
|
||||||
|
/// Methods and trait implementations can be freely added here without breaking end-users.
|
||||||
|
/// If we want to expose new functionality to `#[derive]`, this is the place to do it.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_internal_bitflags {
|
||||||
|
(
|
||||||
|
$InternalBitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt = $value:expr;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
// NOTE: This impl is also used to prevent using bits types from non-primitive types
|
||||||
|
// in the `bitflags` macro. If this approach is changed, this guard will need to be
|
||||||
|
// retained somehow
|
||||||
|
impl $crate::__private::PublicFlags for $PublicBitFlags {
|
||||||
|
type Primitive = $T;
|
||||||
|
type Internal = $InternalBitFlags;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::default::Default for $InternalBitFlags {
|
||||||
|
#[inline]
|
||||||
|
fn default() -> Self {
|
||||||
|
$InternalBitFlags::empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::fmt::Debug for $InternalBitFlags {
|
||||||
|
fn fmt(&self, f: &mut $crate::__private::core::fmt::Formatter<'_>) -> $crate::__private::core::fmt::Result {
|
||||||
|
if self.is_empty() {
|
||||||
|
// If no flags are set then write an empty hex flag to avoid
|
||||||
|
// writing an empty string. In some contexts, like serialization,
|
||||||
|
// an empty string is preferable, but it may be unexpected in
|
||||||
|
// others for a format not to produce any output.
|
||||||
|
//
|
||||||
|
// We can remove this `0x0` and remain compatible with `FromStr`,
|
||||||
|
// because an empty string will still parse to an empty set of flags,
|
||||||
|
// just like `0x0` does.
|
||||||
|
$crate::__private::core::write!(f, "{:#x}", <$T as $crate::Bits>::EMPTY)
|
||||||
|
} else {
|
||||||
|
$crate::__private::core::fmt::Display::fmt(self, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::fmt::Display for $InternalBitFlags {
|
||||||
|
fn fmt(&self, f: &mut $crate::__private::core::fmt::Formatter<'_>) -> $crate::__private::core::fmt::Result {
|
||||||
|
$crate::parser::to_writer(&$PublicBitFlags(*self), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::str::FromStr for $InternalBitFlags {
|
||||||
|
type Err = $crate::parser::ParseError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> $crate::__private::core::result::Result<Self, Self::Err> {
|
||||||
|
$crate::parser::from_str::<$PublicBitFlags>(s).map(|flags| flags.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::convert::AsRef<$T> for $InternalBitFlags {
|
||||||
|
fn as_ref(&self) -> &$T {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::convert::From<$T> for $InternalBitFlags {
|
||||||
|
fn from(bits: $T) -> Self {
|
||||||
|
Self::from_bits_retain(bits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The internal flags type offers a similar API to the public one
|
||||||
|
|
||||||
|
__impl_public_bitflags! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
const $Flag = $value;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_ops! {
|
||||||
|
$InternalBitFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
__impl_public_bitflags_iter! {
|
||||||
|
$InternalBitFlags: $T, $PublicBitFlags
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $InternalBitFlags {
|
||||||
|
/// Returns a mutable reference to the raw value of the flags currently stored.
|
||||||
|
#[inline]
|
||||||
|
pub fn bits_mut(&mut self) -> &mut $T {
|
||||||
|
&mut self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
145
third_party/rust/bitflags/src/iter.rs
vendored
Normal file
145
third_party/rust/bitflags/src/iter.rs
vendored
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/*!
|
||||||
|
Yield the bits of a source flags value in a set of contained flags values.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use crate::{Flag, Flags};
|
||||||
|
|
||||||
|
/**
|
||||||
|
An iterator over flags values.
|
||||||
|
|
||||||
|
This iterator will yield flags values for contained, defined flags first, with any remaining bits yielded
|
||||||
|
as a final flags value.
|
||||||
|
*/
|
||||||
|
pub struct Iter<B: 'static> {
|
||||||
|
inner: IterNames<B>,
|
||||||
|
done: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: Flags> Iter<B> {
|
||||||
|
pub(crate) fn new(flags: &B) -> Self {
|
||||||
|
Iter {
|
||||||
|
inner: IterNames::new(flags),
|
||||||
|
done: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: 'static> Iter<B> {
|
||||||
|
// Used by the `bitflags` macro
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub const fn __private_const_new(flags: &'static [Flag<B>], source: B, remaining: B) -> Self {
|
||||||
|
Iter {
|
||||||
|
inner: IterNames::__private_const_new(flags, source, remaining),
|
||||||
|
done: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: Flags> Iterator for Iter<B> {
|
||||||
|
type Item = B;
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
match self.inner.next() {
|
||||||
|
Some((_, flag)) => Some(flag),
|
||||||
|
None if !self.done => {
|
||||||
|
self.done = true;
|
||||||
|
|
||||||
|
// After iterating through valid names, if there are any bits left over
|
||||||
|
// then return one final value that includes them. This makes `into_iter`
|
||||||
|
// and `from_iter` roundtrip
|
||||||
|
if !self.inner.remaining().is_empty() {
|
||||||
|
Some(B::from_bits_retain(self.inner.remaining.bits()))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
An iterator over flags values.
|
||||||
|
|
||||||
|
This iterator only yields flags values for contained, defined, named flags. Any remaining bits
|
||||||
|
won't be yielded, but can be found with the [`IterNames::remaining`] method.
|
||||||
|
*/
|
||||||
|
pub struct IterNames<B: 'static> {
|
||||||
|
flags: &'static [Flag<B>],
|
||||||
|
idx: usize,
|
||||||
|
source: B,
|
||||||
|
remaining: B,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: Flags> IterNames<B> {
|
||||||
|
pub(crate) fn new(flags: &B) -> Self {
|
||||||
|
IterNames {
|
||||||
|
flags: B::FLAGS,
|
||||||
|
idx: 0,
|
||||||
|
remaining: B::from_bits_retain(flags.bits()),
|
||||||
|
source: B::from_bits_retain(flags.bits()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: 'static> IterNames<B> {
|
||||||
|
// Used by the bitflags macro
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub const fn __private_const_new(flags: &'static [Flag<B>], source: B, remaining: B) -> Self {
|
||||||
|
IterNames {
|
||||||
|
flags,
|
||||||
|
idx: 0,
|
||||||
|
remaining,
|
||||||
|
source,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a flags value of any remaining bits that haven't been yielded yet.
|
||||||
|
///
|
||||||
|
/// Once the iterator has finished, this method can be used to
|
||||||
|
/// check whether or not there are any bits that didn't correspond
|
||||||
|
/// to a contained, defined, named flag remaining.
|
||||||
|
pub fn remaining(&self) -> &B {
|
||||||
|
&self.remaining
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: Flags> Iterator for IterNames<B> {
|
||||||
|
type Item = (&'static str, B);
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
while let Some(flag) = self.flags.get(self.idx) {
|
||||||
|
// Short-circuit if our state is empty
|
||||||
|
if self.remaining.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.idx += 1;
|
||||||
|
|
||||||
|
// Skip unnamed flags
|
||||||
|
if flag.name().is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bits = flag.value().bits();
|
||||||
|
|
||||||
|
// If the flag is set in the original source _and_ it has bits that haven't
|
||||||
|
// been covered by a previous flag yet then yield it. These conditions cover
|
||||||
|
// two cases for multi-bit flags:
|
||||||
|
//
|
||||||
|
// 1. When flags partially overlap, such as `0b00000001` and `0b00000101`, we'll
|
||||||
|
// yield both flags.
|
||||||
|
// 2. When flags fully overlap, such as in convenience flags that are a shorthand for others,
|
||||||
|
// we won't yield both flags.
|
||||||
|
if self.source.contains(B::from_bits_retain(bits))
|
||||||
|
&& self.remaining.intersects(B::from_bits_retain(bits))
|
||||||
|
{
|
||||||
|
self.remaining.remove(B::from_bits_retain(bits));
|
||||||
|
|
||||||
|
return Some((flag.name(), B::from_bits_retain(bits)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
2378
third_party/rust/bitflags/src/lib.rs
vendored
2378
third_party/rust/bitflags/src/lib.rs
vendored
File diff suppressed because it is too large
Load Diff
247
third_party/rust/bitflags/src/parser.rs
vendored
Normal file
247
third_party/rust/bitflags/src/parser.rs
vendored
Normal file
@ -0,0 +1,247 @@
|
|||||||
|
/*!
|
||||||
|
Parsing flags from text.
|
||||||
|
|
||||||
|
Format and parse a flags value as text using the following grammar:
|
||||||
|
|
||||||
|
- _Flags:_ (_Whitespace_ _Flag_ _Whitespace_)`|`*
|
||||||
|
- _Flag:_ _Name_ | _Hex Number_
|
||||||
|
- _Name:_ The name of any defined flag
|
||||||
|
- _Hex Number_: `0x`([0-9a-fA-F])*
|
||||||
|
- _Whitespace_: (\s)*
|
||||||
|
|
||||||
|
As an example, this is how `Flags::A | Flags::B | 0x0c` can be represented as text:
|
||||||
|
|
||||||
|
```text
|
||||||
|
A | B | 0x0c
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, it could be represented without whitespace:
|
||||||
|
|
||||||
|
```text
|
||||||
|
A|B|0x0C
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that identifiers are *case-sensitive*, so the following is *not equivalent*:
|
||||||
|
|
||||||
|
```text
|
||||||
|
a|b|0x0C
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
|
||||||
|
#![allow(clippy::let_unit_value)]
|
||||||
|
|
||||||
|
use core::fmt::{self, Write};
|
||||||
|
|
||||||
|
use crate::{Bits, Flags};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write a flags value as text.
|
||||||
|
|
||||||
|
Any bits that aren't part of a contained flag will be formatted as a hex number.
|
||||||
|
*/
|
||||||
|
pub fn to_writer<B: Flags>(flags: &B, mut writer: impl Write) -> Result<(), fmt::Error>
|
||||||
|
where
|
||||||
|
B::Bits: WriteHex,
|
||||||
|
{
|
||||||
|
// A formatter for bitflags that produces text output like:
|
||||||
|
//
|
||||||
|
// A | B | 0xf6
|
||||||
|
//
|
||||||
|
// The names of set flags are written in a bar-separated-format,
|
||||||
|
// followed by a hex number of any remaining bits that are set
|
||||||
|
// but don't correspond to any flags.
|
||||||
|
|
||||||
|
// Iterate over known flag values
|
||||||
|
let mut first = true;
|
||||||
|
let mut iter = flags.iter_names();
|
||||||
|
for (name, _) in &mut iter {
|
||||||
|
if !first {
|
||||||
|
writer.write_str(" | ")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
first = false;
|
||||||
|
writer.write_str(name)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Append any extra bits that correspond to flags to the end of the format
|
||||||
|
let remaining = iter.remaining().bits();
|
||||||
|
if remaining != B::Bits::EMPTY {
|
||||||
|
if !first {
|
||||||
|
writer.write_str(" | ")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write_str("0x")?;
|
||||||
|
remaining.write_hex(writer)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt::Result::Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct AsDisplay<'a, B>(pub(crate) &'a B);
|
||||||
|
|
||||||
|
impl<'a, B: Flags> fmt::Display for AsDisplay<'a, B>
|
||||||
|
where
|
||||||
|
B::Bits: WriteHex,
|
||||||
|
{
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
to_writer(self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Parse a flags value from text.
|
||||||
|
|
||||||
|
This function will fail on any names that don't correspond to defined flags.
|
||||||
|
Unknown bits will be retained.
|
||||||
|
*/
|
||||||
|
pub fn from_str<B: Flags>(input: &str) -> Result<B, ParseError>
|
||||||
|
where
|
||||||
|
B::Bits: ParseHex,
|
||||||
|
{
|
||||||
|
let mut parsed_flags = B::empty();
|
||||||
|
|
||||||
|
// If the input is empty then return an empty set of flags
|
||||||
|
if input.trim().is_empty() {
|
||||||
|
return Ok(parsed_flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
for flag in input.split('|') {
|
||||||
|
let flag = flag.trim();
|
||||||
|
|
||||||
|
// If the flag is empty then we've got missing input
|
||||||
|
if flag.is_empty() {
|
||||||
|
return Err(ParseError::empty_flag());
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the flag starts with `0x` then it's a hex number
|
||||||
|
// Parse it directly to the underlying bits type
|
||||||
|
let parsed_flag = if let Some(flag) = flag.strip_prefix("0x") {
|
||||||
|
let bits =
|
||||||
|
<B::Bits>::parse_hex(flag).map_err(|_| ParseError::invalid_hex_flag(flag))?;
|
||||||
|
|
||||||
|
B::from_bits_retain(bits)
|
||||||
|
}
|
||||||
|
// Otherwise the flag is a name
|
||||||
|
// The generated flags type will determine whether
|
||||||
|
// or not it's a valid identifier
|
||||||
|
else {
|
||||||
|
B::from_name(flag).ok_or_else(|| ParseError::invalid_named_flag(flag))?
|
||||||
|
};
|
||||||
|
|
||||||
|
parsed_flags.insert(parsed_flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(parsed_flags)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Encode a value as a hex string.
|
||||||
|
|
||||||
|
Implementors of this trait should not write the `0x` prefix.
|
||||||
|
*/
|
||||||
|
pub trait WriteHex {
|
||||||
|
/// Write the value as hex.
|
||||||
|
fn write_hex<W: fmt::Write>(&self, writer: W) -> fmt::Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Parse a value from a hex string.
|
||||||
|
*/
|
||||||
|
pub trait ParseHex {
|
||||||
|
/// Parse the value from hex.
|
||||||
|
fn parse_hex(input: &str) -> Result<Self, ParseError>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An error encountered while parsing flags from text.
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ParseError(ParseErrorKind);
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::enum_variant_names)]
|
||||||
|
enum ParseErrorKind {
|
||||||
|
EmptyFlag,
|
||||||
|
InvalidNamedFlag {
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
got: (),
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
got: String,
|
||||||
|
},
|
||||||
|
InvalidHexFlag {
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
got: (),
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
got: String,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ParseError {
|
||||||
|
/// An invalid hex flag was encountered.
|
||||||
|
pub fn invalid_hex_flag(flag: impl fmt::Display) -> Self {
|
||||||
|
let _flag = flag;
|
||||||
|
|
||||||
|
let got = {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
_flag.to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ParseError(ParseErrorKind::InvalidHexFlag { got })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A named flag that doesn't correspond to any on the flags type was encountered.
|
||||||
|
pub fn invalid_named_flag(flag: impl fmt::Display) -> Self {
|
||||||
|
let _flag = flag;
|
||||||
|
|
||||||
|
let got = {
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
_flag.to_string()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ParseError(ParseErrorKind::InvalidNamedFlag { got })
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A hex or named flag wasn't found between separators.
|
||||||
|
pub const fn empty_flag() -> Self {
|
||||||
|
ParseError(ParseErrorKind::EmptyFlag)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ParseError {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match &self.0 {
|
||||||
|
ParseErrorKind::InvalidNamedFlag { got } => {
|
||||||
|
let _got = got;
|
||||||
|
|
||||||
|
write!(f, "unrecognized named flag")?;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
write!(f, " `{}`", _got)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ParseErrorKind::InvalidHexFlag { got } => {
|
||||||
|
let _got = got;
|
||||||
|
|
||||||
|
write!(f, "invalid hex flag")?;
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
{
|
||||||
|
write!(f, " `{}`", _got)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ParseErrorKind::EmptyFlag => {
|
||||||
|
write!(f, "encountered empty flag")?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
impl std::error::Error for ParseError {}
|
543
third_party/rust/bitflags/src/public.rs
vendored
Normal file
543
third_party/rust/bitflags/src/public.rs
vendored
Normal file
@ -0,0 +1,543 @@
|
|||||||
|
//! Generate the user-facing flags type.
|
||||||
|
//!
|
||||||
|
//! The code here belongs to the end-user, so new trait implementations and methods can't be
|
||||||
|
//! added without potentially breaking users.
|
||||||
|
|
||||||
|
/// Declare the user-facing bitflags struct.
|
||||||
|
///
|
||||||
|
/// This type is guaranteed to be a newtype with a `bitflags`-facing type as its single field.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __declare_public_bitflags {
|
||||||
|
(
|
||||||
|
$(#[$outer:meta])*
|
||||||
|
$vis:vis struct $PublicBitFlags:ident
|
||||||
|
) => {
|
||||||
|
$(#[$outer])*
|
||||||
|
$vis struct $PublicBitFlags(<$PublicBitFlags as $crate::__private::PublicFlags>::Internal);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement functions on the public (user-facing) bitflags type.
|
||||||
|
///
|
||||||
|
/// We need to be careful about adding new methods and trait implementations here because they
|
||||||
|
/// could conflict with items added by the end-user.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_public_bitflags_forward {
|
||||||
|
(
|
||||||
|
$PublicBitFlags:ident: $T:ty, $InternalBitFlags:ident
|
||||||
|
) => {
|
||||||
|
__impl_bitflags! {
|
||||||
|
$PublicBitFlags: $T {
|
||||||
|
fn empty() {
|
||||||
|
Self($InternalBitFlags::empty())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all() {
|
||||||
|
Self($InternalBitFlags::all())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bits(f) {
|
||||||
|
f.0.bits()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits(bits) {
|
||||||
|
match $InternalBitFlags::from_bits(bits) {
|
||||||
|
$crate::__private::core::option::Option::Some(bits) => $crate::__private::core::option::Option::Some(Self(bits)),
|
||||||
|
$crate::__private::core::option::Option::None => $crate::__private::core::option::Option::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_truncate(bits) {
|
||||||
|
Self($InternalBitFlags::from_bits_truncate(bits))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_retain(bits) {
|
||||||
|
Self($InternalBitFlags::from_bits_retain(bits))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_name(name) {
|
||||||
|
match $InternalBitFlags::from_name(name) {
|
||||||
|
$crate::__private::core::option::Option::Some(bits) => $crate::__private::core::option::Option::Some(Self(bits)),
|
||||||
|
$crate::__private::core::option::Option::None => $crate::__private::core::option::Option::None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_empty(f) {
|
||||||
|
f.0.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_all(f) {
|
||||||
|
f.0.is_all()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn intersects(f, other) {
|
||||||
|
f.0.intersects(other.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contains(f, other) {
|
||||||
|
f.0.contains(other.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(f, other) {
|
||||||
|
f.0.insert(other.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(f, other) {
|
||||||
|
f.0.remove(other.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle(f, other) {
|
||||||
|
f.0.toggle(other.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set(f, other, value) {
|
||||||
|
f.0.set(other.0, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn intersection(f, other) {
|
||||||
|
Self(f.0.intersection(other.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn union(f, other) {
|
||||||
|
Self(f.0.union(other.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn difference(f, other) {
|
||||||
|
Self(f.0.difference(other.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn symmetric_difference(f, other) {
|
||||||
|
Self(f.0.symmetric_difference(other.0))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complement(f) {
|
||||||
|
Self(f.0.complement())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement functions on the public (user-facing) bitflags type.
|
||||||
|
///
|
||||||
|
/// We need to be careful about adding new methods and trait implementations here because they
|
||||||
|
/// could conflict with items added by the end-user.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_public_bitflags {
|
||||||
|
(
|
||||||
|
$BitFlags:ident: $T:ty, $PublicBitFlags:ident {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt = $value:expr;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
__impl_bitflags! {
|
||||||
|
$BitFlags: $T {
|
||||||
|
fn empty() {
|
||||||
|
Self(<$T as $crate::Bits>::EMPTY)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all() {
|
||||||
|
let mut truncated = <$T as $crate::Bits>::EMPTY;
|
||||||
|
let mut i = 0;
|
||||||
|
|
||||||
|
$(
|
||||||
|
__bitflags_expr_safe_attrs!(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
{{
|
||||||
|
let flag = <$PublicBitFlags as $crate::Flags>::FLAGS[i].value().bits();
|
||||||
|
|
||||||
|
truncated = truncated | flag;
|
||||||
|
i += 1;
|
||||||
|
}}
|
||||||
|
);
|
||||||
|
)*
|
||||||
|
|
||||||
|
let _ = i;
|
||||||
|
Self::from_bits_retain(truncated)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bits(f) {
|
||||||
|
f.0
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits(bits) {
|
||||||
|
let truncated = Self::from_bits_truncate(bits).0;
|
||||||
|
|
||||||
|
if truncated == bits {
|
||||||
|
$crate::__private::core::option::Option::Some(Self(bits))
|
||||||
|
} else {
|
||||||
|
$crate::__private::core::option::Option::None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_truncate(bits) {
|
||||||
|
Self(bits & Self::all().bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_retain(bits) {
|
||||||
|
Self(bits)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_name(name) {
|
||||||
|
$(
|
||||||
|
__bitflags_flag!({
|
||||||
|
name: $Flag,
|
||||||
|
named: {
|
||||||
|
__bitflags_expr_safe_attrs!(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
{
|
||||||
|
if name == $crate::__private::core::stringify!($Flag) {
|
||||||
|
return $crate::__private::core::option::Option::Some(Self($PublicBitFlags::$Flag.bits()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
unnamed: {},
|
||||||
|
});
|
||||||
|
)*
|
||||||
|
|
||||||
|
let _ = name;
|
||||||
|
$crate::__private::core::option::Option::None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_empty(f) {
|
||||||
|
f.bits() == <$T as $crate::Bits>::EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_all(f) {
|
||||||
|
// NOTE: We check against `Self::all` here, not `Self::Bits::ALL`
|
||||||
|
// because the set of all flags may not use all bits
|
||||||
|
Self::all().bits() | f.bits() == f.bits()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn intersects(f, other) {
|
||||||
|
f.bits() & other.bits() != <$T as $crate::Bits>::EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
fn contains(f, other) {
|
||||||
|
f.bits() & other.bits() == other.bits()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn insert(f, other) {
|
||||||
|
*f = Self::from_bits_retain(f.bits()).union(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn remove(f, other) {
|
||||||
|
*f = Self::from_bits_retain(f.bits()).difference(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn toggle(f, other) {
|
||||||
|
*f = Self::from_bits_retain(f.bits()).symmetric_difference(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set(f, other, value) {
|
||||||
|
if value {
|
||||||
|
f.insert(other);
|
||||||
|
} else {
|
||||||
|
f.remove(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn intersection(f, other) {
|
||||||
|
Self::from_bits_retain(f.bits() & other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn union(f, other) {
|
||||||
|
Self::from_bits_retain(f.bits() | other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn difference(f, other) {
|
||||||
|
Self::from_bits_retain(f.bits() & !other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn symmetric_difference(f, other) {
|
||||||
|
Self::from_bits_retain(f.bits() ^ other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn complement(f) {
|
||||||
|
Self::from_bits_truncate(!f.bits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement iterators on the public (user-facing) bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_public_bitflags_iter {
|
||||||
|
($BitFlags:ident: $T:ty, $PublicBitFlags:ident) => {
|
||||||
|
impl $BitFlags {
|
||||||
|
/// Yield a set of contained flags values.
|
||||||
|
///
|
||||||
|
/// Each yielded flags value will correspond to a defined named flag. Any unknown bits
|
||||||
|
/// will be yielded together as a final flags value.
|
||||||
|
#[inline]
|
||||||
|
pub const fn iter(&self) -> $crate::iter::Iter<$PublicBitFlags> {
|
||||||
|
$crate::iter::Iter::__private_const_new(
|
||||||
|
<$PublicBitFlags as $crate::Flags>::FLAGS,
|
||||||
|
$PublicBitFlags::from_bits_retain(self.bits()),
|
||||||
|
$PublicBitFlags::from_bits_retain(self.bits()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Yield a set of contained named flags values.
|
||||||
|
///
|
||||||
|
/// This method is like [`iter`](#method.iter), except only yields bits in contained named flags.
|
||||||
|
/// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
|
||||||
|
#[inline]
|
||||||
|
pub const fn iter_names(&self) -> $crate::iter::IterNames<$PublicBitFlags> {
|
||||||
|
$crate::iter::IterNames::__private_const_new(
|
||||||
|
<$PublicBitFlags as $crate::Flags>::FLAGS,
|
||||||
|
$PublicBitFlags::from_bits_retain(self.bits()),
|
||||||
|
$PublicBitFlags::from_bits_retain(self.bits()),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::iter::IntoIterator for $BitFlags {
|
||||||
|
type Item = $PublicBitFlags;
|
||||||
|
type IntoIter = $crate::iter::Iter<$PublicBitFlags>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement traits on the public (user-facing) bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_public_bitflags_ops {
|
||||||
|
($PublicBitFlags:ident) => {
|
||||||
|
impl $crate::__private::core::fmt::Binary for $PublicBitFlags {
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
f: &mut $crate::__private::core::fmt::Formatter,
|
||||||
|
) -> $crate::__private::core::fmt::Result {
|
||||||
|
$crate::__private::core::fmt::Binary::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::fmt::Octal for $PublicBitFlags {
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
f: &mut $crate::__private::core::fmt::Formatter,
|
||||||
|
) -> $crate::__private::core::fmt::Result {
|
||||||
|
$crate::__private::core::fmt::Octal::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::fmt::LowerHex for $PublicBitFlags {
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
f: &mut $crate::__private::core::fmt::Formatter,
|
||||||
|
) -> $crate::__private::core::fmt::Result {
|
||||||
|
$crate::__private::core::fmt::LowerHex::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::fmt::UpperHex for $PublicBitFlags {
|
||||||
|
fn fmt(
|
||||||
|
&self,
|
||||||
|
f: &mut $crate::__private::core::fmt::Formatter,
|
||||||
|
) -> $crate::__private::core::fmt::Result {
|
||||||
|
$crate::__private::core::fmt::UpperHex::fmt(&self.0, f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitOr for $PublicBitFlags {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
/// The bitwise or (`|`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitor(self, other: $PublicBitFlags) -> Self {
|
||||||
|
self.union(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitOrAssign for $PublicBitFlags {
|
||||||
|
/// The bitwise or (`|`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitor_assign(&mut self, other: Self) {
|
||||||
|
self.insert(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitXor for $PublicBitFlags {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
/// The bitwise exclusive-or (`^`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitxor(self, other: Self) -> Self {
|
||||||
|
self.symmetric_difference(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitXorAssign for $PublicBitFlags {
|
||||||
|
/// The bitwise exclusive-or (`^`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitxor_assign(&mut self, other: Self) {
|
||||||
|
self.toggle(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitAnd for $PublicBitFlags {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
/// The bitwise and (`&`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitand(self, other: Self) -> Self {
|
||||||
|
self.intersection(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::BitAndAssign for $PublicBitFlags {
|
||||||
|
/// The bitwise and (`&`) of the bits in two flags values.
|
||||||
|
#[inline]
|
||||||
|
fn bitand_assign(&mut self, other: Self) {
|
||||||
|
*self = Self::from_bits_retain(self.bits()).intersection(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::Sub for $PublicBitFlags {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
/// The intersection of a source flags value with the complement of a target flags value (`&!`).
|
||||||
|
///
|
||||||
|
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
|
||||||
|
/// `difference` won't truncate `other`, but the `!` operator will.
|
||||||
|
#[inline]
|
||||||
|
fn sub(self, other: Self) -> Self {
|
||||||
|
self.difference(other)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::SubAssign for $PublicBitFlags {
|
||||||
|
/// The intersection of a source flags value with the complement of a target flags value (`&!`).
|
||||||
|
///
|
||||||
|
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
|
||||||
|
/// `difference` won't truncate `other`, but the `!` operator will.
|
||||||
|
#[inline]
|
||||||
|
fn sub_assign(&mut self, other: Self) {
|
||||||
|
self.remove(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::ops::Not for $PublicBitFlags {
|
||||||
|
type Output = Self;
|
||||||
|
|
||||||
|
/// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
|
||||||
|
#[inline]
|
||||||
|
fn not(self) -> Self {
|
||||||
|
self.complement()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::iter::Extend<$PublicBitFlags> for $PublicBitFlags {
|
||||||
|
/// The bitwise or (`|`) of the bits in each flags value.
|
||||||
|
fn extend<T: $crate::__private::core::iter::IntoIterator<Item = Self>>(
|
||||||
|
&mut self,
|
||||||
|
iterator: T,
|
||||||
|
) {
|
||||||
|
for item in iterator {
|
||||||
|
self.insert(item)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::__private::core::iter::FromIterator<$PublicBitFlags> for $PublicBitFlags {
|
||||||
|
/// The bitwise or (`|`) of the bits in each flags value.
|
||||||
|
fn from_iter<T: $crate::__private::core::iter::IntoIterator<Item = Self>>(
|
||||||
|
iterator: T,
|
||||||
|
) -> Self {
|
||||||
|
use $crate::__private::core::iter::Extend;
|
||||||
|
|
||||||
|
let mut result = Self::empty();
|
||||||
|
result.extend(iterator);
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Implement constants on the public (user-facing) bitflags type.
|
||||||
|
#[macro_export(local_inner_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __impl_public_bitflags_consts {
|
||||||
|
(
|
||||||
|
$PublicBitFlags:ident: $T:ty {
|
||||||
|
$(
|
||||||
|
$(#[$inner:ident $($args:tt)*])*
|
||||||
|
const $Flag:tt = $value:expr;
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
) => {
|
||||||
|
impl $PublicBitFlags {
|
||||||
|
$(
|
||||||
|
__bitflags_flag!({
|
||||||
|
name: $Flag,
|
||||||
|
named: {
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
#[allow(
|
||||||
|
deprecated,
|
||||||
|
non_upper_case_globals,
|
||||||
|
)]
|
||||||
|
pub const $Flag: Self = Self::from_bits_retain($value);
|
||||||
|
},
|
||||||
|
unnamed: {},
|
||||||
|
});
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
|
||||||
|
impl $crate::Flags for $PublicBitFlags {
|
||||||
|
const FLAGS: &'static [$crate::Flag<$PublicBitFlags>] = &[
|
||||||
|
$(
|
||||||
|
__bitflags_flag!({
|
||||||
|
name: $Flag,
|
||||||
|
named: {
|
||||||
|
__bitflags_expr_safe_attrs!(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
{
|
||||||
|
#[allow(
|
||||||
|
deprecated,
|
||||||
|
non_upper_case_globals,
|
||||||
|
)]
|
||||||
|
$crate::Flag::new($crate::__private::core::stringify!($Flag), $PublicBitFlags::$Flag)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
unnamed: {
|
||||||
|
__bitflags_expr_safe_attrs!(
|
||||||
|
$(#[$inner $($args)*])*
|
||||||
|
{
|
||||||
|
#[allow(
|
||||||
|
deprecated,
|
||||||
|
non_upper_case_globals,
|
||||||
|
)]
|
||||||
|
$crate::Flag::new("", $PublicBitFlags::from_bits_retain($value))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
)*
|
||||||
|
];
|
||||||
|
|
||||||
|
type Bits = $T;
|
||||||
|
|
||||||
|
fn bits(&self) -> $T {
|
||||||
|
$PublicBitFlags::bits(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_bits_retain(bits: $T) -> $PublicBitFlags {
|
||||||
|
$PublicBitFlags::from_bits_retain(bits)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
131
third_party/rust/bitflags/src/tests.rs
vendored
Normal file
131
third_party/rust/bitflags/src/tests.rs
vendored
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
mod all;
|
||||||
|
mod bits;
|
||||||
|
mod complement;
|
||||||
|
mod contains;
|
||||||
|
mod difference;
|
||||||
|
mod empty;
|
||||||
|
mod eq;
|
||||||
|
mod extend;
|
||||||
|
mod flags;
|
||||||
|
mod fmt;
|
||||||
|
mod from_bits;
|
||||||
|
mod from_bits_retain;
|
||||||
|
mod from_bits_truncate;
|
||||||
|
mod from_name;
|
||||||
|
mod insert;
|
||||||
|
mod intersection;
|
||||||
|
mod intersects;
|
||||||
|
mod is_all;
|
||||||
|
mod is_empty;
|
||||||
|
mod iter;
|
||||||
|
mod parser;
|
||||||
|
mod remove;
|
||||||
|
mod symmetric_difference;
|
||||||
|
mod union;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestFlags: u8 {
|
||||||
|
/// 1
|
||||||
|
const A = 1;
|
||||||
|
|
||||||
|
/// 1 << 1
|
||||||
|
const B = 1 << 1;
|
||||||
|
|
||||||
|
/// 1 << 2
|
||||||
|
const C = 1 << 2;
|
||||||
|
|
||||||
|
/// 1 | (1 << 1) | (1 << 2)
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestFlagsInvert: u8 {
|
||||||
|
/// 1 | (1 << 1) | (1 << 2)
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
|
||||||
|
/// 1
|
||||||
|
const A = 1;
|
||||||
|
|
||||||
|
/// 1 << 1
|
||||||
|
const B = 1 << 1;
|
||||||
|
|
||||||
|
/// 1 << 2
|
||||||
|
const C = 1 << 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestZero: u8 {
|
||||||
|
/// 0
|
||||||
|
const ZERO = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestZeroOne: u8 {
|
||||||
|
/// 0
|
||||||
|
const ZERO = 0;
|
||||||
|
|
||||||
|
/// 1
|
||||||
|
const ONE = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestUnicode: u8 {
|
||||||
|
/// 1
|
||||||
|
const 一 = 1;
|
||||||
|
|
||||||
|
/// 2
|
||||||
|
const 二 = 1 << 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestEmpty: u8 {}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestOverlapping: u8 {
|
||||||
|
/// 1 | (1 << 1)
|
||||||
|
const AB = 1 | (1 << 1);
|
||||||
|
|
||||||
|
/// (1 << 1) | (1 << 2)
|
||||||
|
const BC = (1 << 1) | (1 << 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestOverlappingFull: u8 {
|
||||||
|
/// 1
|
||||||
|
const A = 1;
|
||||||
|
|
||||||
|
/// 1
|
||||||
|
const B = 1;
|
||||||
|
|
||||||
|
/// 1
|
||||||
|
const C = 1;
|
||||||
|
|
||||||
|
/// 2
|
||||||
|
const D = 1 << 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestExternal: u8 {
|
||||||
|
/// 1
|
||||||
|
const A = 1;
|
||||||
|
|
||||||
|
/// 1 << 1
|
||||||
|
const B = 1 << 1;
|
||||||
|
|
||||||
|
/// 1 << 2
|
||||||
|
const C = 1 << 2;
|
||||||
|
|
||||||
|
/// 1 | (1 << 1) | (1 << 2)
|
||||||
|
const ABC = Self::A.bits() | Self::B.bits() | Self::C.bits();
|
||||||
|
|
||||||
|
/// External
|
||||||
|
const _ = !0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
|
||||||
|
pub struct TestExternalFull: u8 {
|
||||||
|
/// External
|
||||||
|
const _ = !0;
|
||||||
|
}
|
||||||
|
}
|
430
third_party/rust/bitflags/src/traits.rs
vendored
Normal file
430
third_party/rust/bitflags/src/traits.rs
vendored
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
use core::{
|
||||||
|
fmt,
|
||||||
|
ops::{BitAnd, BitOr, BitXor, Not},
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
iter,
|
||||||
|
parser::{ParseError, ParseHex, WriteHex},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
A defined flags value that may be named or unnamed.
|
||||||
|
*/
|
||||||
|
pub struct Flag<B> {
|
||||||
|
name: &'static str,
|
||||||
|
value: B,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B> Flag<B> {
|
||||||
|
/**
|
||||||
|
Define a flag.
|
||||||
|
|
||||||
|
If `name` is non-empty then the flag is named, otherwise it's unnamed.
|
||||||
|
*/
|
||||||
|
pub const fn new(name: &'static str, value: B) -> Self {
|
||||||
|
Flag { name, value }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the name of this flag.
|
||||||
|
|
||||||
|
If the flag is unnamed then the returned string will be empty.
|
||||||
|
*/
|
||||||
|
pub const fn name(&self) -> &'static str {
|
||||||
|
self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the flags value of this flag.
|
||||||
|
*/
|
||||||
|
pub const fn value(&self) -> &B {
|
||||||
|
&self.value
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Whether the flag is named.
|
||||||
|
|
||||||
|
If [`Flag::name`] returns a non-empty string then this method will return `true`.
|
||||||
|
*/
|
||||||
|
pub const fn is_named(&self) -> bool {
|
||||||
|
!self.name.is_empty()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Whether the flag is unnamed.
|
||||||
|
|
||||||
|
If [`Flag::name`] returns a non-empty string then this method will return `false`.
|
||||||
|
*/
|
||||||
|
pub const fn is_unnamed(&self) -> bool {
|
||||||
|
self.name.is_empty()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
A set of defined flags using a bits type as storage.
|
||||||
|
|
||||||
|
## Implementing `Flags`
|
||||||
|
|
||||||
|
This trait is implemented by the [`bitflags`](macro.bitflags.html) macro:
|
||||||
|
|
||||||
|
```
|
||||||
|
use bitflags::bitflags;
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
struct MyFlags: u8 {
|
||||||
|
const A = 1;
|
||||||
|
const B = 1 << 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
It can also be implemented manually:
|
||||||
|
|
||||||
|
```
|
||||||
|
use bitflags::{Flag, Flags};
|
||||||
|
|
||||||
|
struct MyFlags(u8);
|
||||||
|
|
||||||
|
impl Flags for MyFlags {
|
||||||
|
const FLAGS: &'static [Flag<Self>] = &[
|
||||||
|
Flag::new("A", MyFlags(1)),
|
||||||
|
Flag::new("B", MyFlags(1 << 1)),
|
||||||
|
];
|
||||||
|
|
||||||
|
type Bits = u8;
|
||||||
|
|
||||||
|
fn from_bits_retain(bits: Self::Bits) -> Self {
|
||||||
|
MyFlags(bits)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bits(&self) -> Self::Bits {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using `Flags`
|
||||||
|
|
||||||
|
The `Flags` trait can be used generically to work with any flags types. In this example,
|
||||||
|
we can count the number of defined named flags:
|
||||||
|
|
||||||
|
```
|
||||||
|
# use bitflags::{bitflags, Flags};
|
||||||
|
fn defined_flags<F: Flags>() -> usize {
|
||||||
|
F::FLAGS.iter().filter(|f| f.is_named()).count()
|
||||||
|
}
|
||||||
|
|
||||||
|
bitflags! {
|
||||||
|
struct MyFlags: u8 {
|
||||||
|
const A = 1;
|
||||||
|
const B = 1 << 1;
|
||||||
|
const C = 1 << 2;
|
||||||
|
|
||||||
|
const _ = !0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_eq!(3, defined_flags::<MyFlags>());
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
pub trait Flags: Sized + 'static {
|
||||||
|
/// The set of defined flags.
|
||||||
|
const FLAGS: &'static [Flag<Self>];
|
||||||
|
|
||||||
|
/// The underlying bits type.
|
||||||
|
type Bits: Bits;
|
||||||
|
|
||||||
|
/// Get a flags value with all bits unset.
|
||||||
|
fn empty() -> Self {
|
||||||
|
Self::from_bits_retain(Self::Bits::EMPTY)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get a flags value with all known bits set.
|
||||||
|
fn all() -> Self {
|
||||||
|
let mut truncated = Self::Bits::EMPTY;
|
||||||
|
|
||||||
|
for flag in Self::FLAGS.iter() {
|
||||||
|
truncated = truncated | flag.value().bits();
|
||||||
|
}
|
||||||
|
|
||||||
|
Self::from_bits_retain(truncated)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the underlying bits value.
|
||||||
|
///
|
||||||
|
/// The returned value is exactly the bits set in this flags value.
|
||||||
|
fn bits(&self) -> Self::Bits;
|
||||||
|
|
||||||
|
/// Convert from a bits value.
|
||||||
|
///
|
||||||
|
/// This method will return `None` if any unknown bits are set.
|
||||||
|
fn from_bits(bits: Self::Bits) -> Option<Self> {
|
||||||
|
let truncated = Self::from_bits_truncate(bits);
|
||||||
|
|
||||||
|
if truncated.bits() == bits {
|
||||||
|
Some(truncated)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from a bits value, unsetting any unknown bits.
|
||||||
|
fn from_bits_truncate(bits: Self::Bits) -> Self {
|
||||||
|
Self::from_bits_retain(bits & Self::all().bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from a bits value exactly.
|
||||||
|
fn from_bits_retain(bits: Self::Bits) -> Self;
|
||||||
|
|
||||||
|
/// Get a flags value with the bits of a flag with the given name set.
|
||||||
|
///
|
||||||
|
/// This method will return `None` if `name` is empty or doesn't
|
||||||
|
/// correspond to any named flag.
|
||||||
|
fn from_name(name: &str) -> Option<Self> {
|
||||||
|
// Don't parse empty names as empty flags
|
||||||
|
if name.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
for flag in Self::FLAGS {
|
||||||
|
if flag.name() == name {
|
||||||
|
return Some(Self::from_bits_retain(flag.value().bits()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Yield a set of contained flags values.
|
||||||
|
///
|
||||||
|
/// Each yielded flags value will correspond to a defined named flag. Any unknown bits
|
||||||
|
/// will be yielded together as a final flags value.
|
||||||
|
fn iter(&self) -> iter::Iter<Self> {
|
||||||
|
iter::Iter::new(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Yield a set of contained named flags values.
|
||||||
|
///
|
||||||
|
/// This method is like [`Flags::iter`], except only yields bits in contained named flags.
|
||||||
|
/// Any unknown bits, or bits not corresponding to a contained flag will not be yielded.
|
||||||
|
fn iter_names(&self) -> iter::IterNames<Self> {
|
||||||
|
iter::IterNames::new(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether all bits in this flags value are unset.
|
||||||
|
fn is_empty(&self) -> bool {
|
||||||
|
self.bits() == Self::Bits::EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether all known bits in this flags value are set.
|
||||||
|
fn is_all(&self) -> bool {
|
||||||
|
// NOTE: We check against `Self::all` here, not `Self::Bits::ALL`
|
||||||
|
// because the set of all flags may not use all bits
|
||||||
|
Self::all().bits() | self.bits() == self.bits()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether any set bits in a source flags value are also set in a target flags value.
|
||||||
|
fn intersects(&self, other: Self) -> bool
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.bits() & other.bits() != Self::Bits::EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether all set bits in a source flags value are also set in a target flags value.
|
||||||
|
fn contains(&self, other: Self) -> bool
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
self.bits() & other.bits() == other.bits()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise or (`|`) of the bits in two flags values.
|
||||||
|
fn insert(&mut self, other: Self)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
*self = Self::from_bits_retain(self.bits()).union(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The intersection of a source flags value with the complement of a target flags value (`&!`).
|
||||||
|
///
|
||||||
|
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
|
||||||
|
/// `remove` won't truncate `other`, but the `!` operator will.
|
||||||
|
fn remove(&mut self, other: Self)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
*self = Self::from_bits_retain(self.bits()).difference(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise exclusive-or (`^`) of the bits in two flags values.
|
||||||
|
fn toggle(&mut self, other: Self)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
*self = Self::from_bits_retain(self.bits()).symmetric_difference(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Call [`Flags::insert`] when `value` is `true` or [`Flags::remove`] when `value` is `false`.
|
||||||
|
fn set(&mut self, other: Self, value: bool)
|
||||||
|
where
|
||||||
|
Self: Sized,
|
||||||
|
{
|
||||||
|
if value {
|
||||||
|
self.insert(other);
|
||||||
|
} else {
|
||||||
|
self.remove(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise and (`&`) of the bits in two flags values.
|
||||||
|
#[must_use]
|
||||||
|
fn intersection(self, other: Self) -> Self {
|
||||||
|
Self::from_bits_retain(self.bits() & other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise or (`|`) of the bits in two flags values.
|
||||||
|
#[must_use]
|
||||||
|
fn union(self, other: Self) -> Self {
|
||||||
|
Self::from_bits_retain(self.bits() | other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The intersection of a source flags value with the complement of a target flags value (`&!`).
|
||||||
|
///
|
||||||
|
/// This method is not equivalent to `self & !other` when `other` has unknown bits set.
|
||||||
|
/// `difference` won't truncate `other`, but the `!` operator will.
|
||||||
|
#[must_use]
|
||||||
|
fn difference(self, other: Self) -> Self {
|
||||||
|
Self::from_bits_retain(self.bits() & !other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise exclusive-or (`^`) of the bits in two flags values.
|
||||||
|
#[must_use]
|
||||||
|
fn symmetric_difference(self, other: Self) -> Self {
|
||||||
|
Self::from_bits_retain(self.bits() ^ other.bits())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The bitwise negation (`!`) of the bits in a flags value, truncating the result.
|
||||||
|
#[must_use]
|
||||||
|
fn complement(self) -> Self {
|
||||||
|
Self::from_bits_truncate(!self.bits())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
A bits type that can be used as storage for a flags type.
|
||||||
|
*/
|
||||||
|
pub trait Bits:
|
||||||
|
Clone
|
||||||
|
+ Copy
|
||||||
|
+ PartialEq
|
||||||
|
+ BitAnd<Output = Self>
|
||||||
|
+ BitOr<Output = Self>
|
||||||
|
+ BitXor<Output = Self>
|
||||||
|
+ Not<Output = Self>
|
||||||
|
+ Sized
|
||||||
|
+ 'static
|
||||||
|
{
|
||||||
|
/// A value with all bits unset.
|
||||||
|
const EMPTY: Self;
|
||||||
|
|
||||||
|
/// A value with all bits set.
|
||||||
|
const ALL: Self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not re-exported: prevent custom `Bits` impls being used in the `bitflags!` macro,
|
||||||
|
// or they may fail to compile based on crate features
|
||||||
|
pub trait Primitive {}
|
||||||
|
|
||||||
|
macro_rules! impl_bits {
|
||||||
|
($($u:ty, $i:ty,)*) => {
|
||||||
|
$(
|
||||||
|
impl Bits for $u {
|
||||||
|
const EMPTY: $u = 0;
|
||||||
|
const ALL: $u = <$u>::MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Bits for $i {
|
||||||
|
const EMPTY: $i = 0;
|
||||||
|
const ALL: $i = <$u>::MAX as $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ParseHex for $u {
|
||||||
|
fn parse_hex(input: &str) -> Result<Self, ParseError> {
|
||||||
|
<$u>::from_str_radix(input, 16).map_err(|_| ParseError::invalid_hex_flag(input))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ParseHex for $i {
|
||||||
|
fn parse_hex(input: &str) -> Result<Self, ParseError> {
|
||||||
|
<$i>::from_str_radix(input, 16).map_err(|_| ParseError::invalid_hex_flag(input))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WriteHex for $u {
|
||||||
|
fn write_hex<W: fmt::Write>(&self, mut writer: W) -> fmt::Result {
|
||||||
|
write!(writer, "{:x}", self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl WriteHex for $i {
|
||||||
|
fn write_hex<W: fmt::Write>(&self, mut writer: W) -> fmt::Result {
|
||||||
|
write!(writer, "{:x}", self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Primitive for $i {}
|
||||||
|
impl Primitive for $u {}
|
||||||
|
)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl_bits! {
|
||||||
|
u8, i8,
|
||||||
|
u16, i16,
|
||||||
|
u32, i32,
|
||||||
|
u64, i64,
|
||||||
|
u128, i128,
|
||||||
|
usize, isize,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trait for referencing the `bitflags`-owned internal type
|
||||||
|
/// without exposing it publicly.
|
||||||
|
pub trait PublicFlags {
|
||||||
|
/// The type of the underlying storage.
|
||||||
|
type Primitive: Primitive;
|
||||||
|
|
||||||
|
/// The type of the internal field on the generated flags type.
|
||||||
|
type Internal;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[deprecated(note = "use the `Flags` trait instead")]
|
||||||
|
pub trait BitFlags: ImplementedByBitFlagsMacro + Flags {
|
||||||
|
/// An iterator over enabled flags in an instance of the type.
|
||||||
|
type Iter: Iterator<Item = Self>;
|
||||||
|
|
||||||
|
/// An iterator over the raw names and bits for enabled flags in an instance of the type.
|
||||||
|
type IterNames: Iterator<Item = (&'static str, Self)>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(deprecated)]
|
||||||
|
impl<B: Flags> BitFlags for B {
|
||||||
|
type Iter = iter::Iter<Self>;
|
||||||
|
type IterNames = iter::IterNames<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<B: Flags> ImplementedByBitFlagsMacro for B {}
|
||||||
|
|
||||||
|
/// A marker trait that signals that an implementation of `BitFlags` came from the `bitflags!` macro.
|
||||||
|
///
|
||||||
|
/// There's nothing stopping an end-user from implementing this trait, but we don't guarantee their
|
||||||
|
/// manual implementations won't break between non-breaking releases.
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub trait ImplementedByBitFlagsMacro {}
|
||||||
|
|
||||||
|
pub(crate) mod __private {
|
||||||
|
pub use super::{ImplementedByBitFlagsMacro, PublicFlags};
|
||||||
|
}
|
20
third_party/rust/bitflags/tests/basic.rs
vendored
20
third_party/rust/bitflags/tests/basic.rs
vendored
@ -1,20 +0,0 @@
|
|||||||
#![no_std]
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
/// baz
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
#[doc = "bar"]
|
|
||||||
const B = 0b00000010;
|
|
||||||
const C = 0b00000100;
|
|
||||||
#[doc = "foo"]
|
|
||||||
const ABC = Flags::A.bits | Flags::B.bits | Flags::C.bits;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn basic() {
|
|
||||||
assert_eq!(Flags::ABC, Flags::A | Flags::B | Flags::C);
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,27 +0,0 @@
|
|||||||
error[E0119]: conflicting implementations of trait `std::clone::Clone` for type `Flags`
|
|
||||||
--> $DIR/copy.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(Clone, Copy)]
|
|
||||||
| | ----- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `Flags`
|
|
||||||
--> $DIR/copy.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(Clone, Copy)]
|
|
||||||
| | ---- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,10 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
#[derive(PartialEq, Eq)]
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,55 +0,0 @@
|
|||||||
error[E0119]: conflicting implementations of trait `std::cmp::PartialEq` for type `Flags`
|
|
||||||
--> $DIR/eq.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(PartialEq, Eq)]
|
|
||||||
| | --------- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0119]: conflicting implementations of trait `std::cmp::Eq` for type `Flags`
|
|
||||||
--> $DIR/eq.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(PartialEq, Eq)]
|
|
||||||
| | -- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0119]: conflicting implementations of trait `std::marker::StructuralPartialEq` for type `Flags`
|
|
||||||
--> $DIR/eq.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(PartialEq, Eq)]
|
|
||||||
| | --------- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0119]: conflicting implementations of trait `std::marker::StructuralEq` for type `Flags`
|
|
||||||
--> $DIR/eq.rs:3:1
|
|
||||||
|
|
|
||||||
3 | / bitflags! {
|
|
||||||
4 | | #[derive(PartialEq, Eq)]
|
|
||||||
| | -- first implementation here
|
|
||||||
5 | | struct Flags: u32 {
|
|
||||||
6 | | const A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
8 | | }
|
|
||||||
| |_^ conflicting implementation for `Flags`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,123 +0,0 @@
|
|||||||
use std::{
|
|
||||||
fmt::{
|
|
||||||
self,
|
|
||||||
Debug,
|
|
||||||
Display,
|
|
||||||
LowerHex,
|
|
||||||
UpperHex,
|
|
||||||
Octal,
|
|
||||||
Binary,
|
|
||||||
},
|
|
||||||
ops::{
|
|
||||||
BitAnd,
|
|
||||||
BitOr,
|
|
||||||
BitXor,
|
|
||||||
BitAndAssign,
|
|
||||||
BitOrAssign,
|
|
||||||
BitXorAssign,
|
|
||||||
Not,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
// Ideally we'd actually want this to work, but currently need something like `num`'s `Zero`
|
|
||||||
// With some design work it could be made possible
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
||||||
struct MyInt(u8);
|
|
||||||
|
|
||||||
impl BitAnd for MyInt {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn bitand(self, other: Self) -> Self {
|
|
||||||
MyInt(self.0 & other.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitOr for MyInt {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn bitor(self, other: Self) -> Self {
|
|
||||||
MyInt(self.0 | other.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitXor for MyInt {
|
|
||||||
type Output = Self;
|
|
||||||
|
|
||||||
fn bitxor(self, other: Self) -> Self {
|
|
||||||
MyInt(self.0 ^ other.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitAndAssign for MyInt {
|
|
||||||
fn bitand_assign(&mut self, other: Self) {
|
|
||||||
self.0 &= other.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitOrAssign for MyInt {
|
|
||||||
fn bitor_assign(&mut self, other: Self) {
|
|
||||||
self.0 |= other.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BitXorAssign for MyInt {
|
|
||||||
fn bitxor_assign(&mut self, other: Self) {
|
|
||||||
self.0 ^= other.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Debug for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
Debug::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
Display::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LowerHex for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
LowerHex::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UpperHex for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
UpperHex::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Octal for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
Octal::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Binary for MyInt {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
Binary::fmt(&self.0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Not for MyInt {
|
|
||||||
type Output = MyInt;
|
|
||||||
|
|
||||||
fn not(self) -> Self {
|
|
||||||
MyInt(!self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Flags128: MyInt {
|
|
||||||
const A = MyInt(0b0000_0001u8);
|
|
||||||
const B = MyInt(0b0000_0010u8);
|
|
||||||
const C = MyInt(0b0000_0100u8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,27 +0,0 @@
|
|||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/all_defined.rs:115:1
|
|
||||||
|
|
|
||||||
115 | / bitflags! {
|
|
||||||
116 | | struct Flags128: MyInt {
|
|
||||||
117 | | const A = MyInt(0b0000_0001u8);
|
|
||||||
118 | | const B = MyInt(0b0000_0010u8);
|
|
||||||
119 | | const C = MyInt(0b0000_0100u8);
|
|
||||||
120 | | }
|
|
||||||
121 | | }
|
|
||||||
| |_^ expected struct `MyInt`, found integer
|
|
||||||
|
|
|
||||||
= note: this error originates in the macro `__impl_all_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/all_defined.rs:115:1
|
|
||||||
|
|
|
||||||
115 | / bitflags! {
|
|
||||||
116 | | struct Flags128: MyInt {
|
|
||||||
117 | | const A = MyInt(0b0000_0001u8);
|
|
||||||
118 | | const B = MyInt(0b0000_0010u8);
|
|
||||||
119 | | const C = MyInt(0b0000_0100u8);
|
|
||||||
120 | | }
|
|
||||||
121 | | }
|
|
||||||
| |_^ expected struct `MyInt`, found integer
|
|
||||||
|
|
|
||||||
= note: this error originates in the macro `__impl_bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,13 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
struct MyInt(u8);
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Flags128: MyInt {
|
|
||||||
const A = MyInt(0b0000_0001);
|
|
||||||
const B = MyInt(0b0000_0010);
|
|
||||||
const C = MyInt(0b0000_0100);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,13 +0,0 @@
|
|||||||
error[E0204]: the trait `Copy` may not be implemented for this type
|
|
||||||
--> $DIR/all_missing.rs:5:1
|
|
||||||
|
|
|
||||||
5 | / bitflags! {
|
|
||||||
6 | | struct Flags128: MyInt {
|
|
||||||
7 | | const A = MyInt(0b0000_0001);
|
|
||||||
8 | | const B = MyInt(0b0000_0010);
|
|
||||||
9 | | const C = MyInt(0b0000_0100);
|
|
||||||
10 | | }
|
|
||||||
11 | | }
|
|
||||||
| |_^ this field does not implement `Copy`
|
|
||||||
|
|
|
||||||
= note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,13 +0,0 @@
|
|||||||
mod example {
|
|
||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
pub struct Flags1: u32 {
|
|
||||||
const FLAG_A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let flag1 = example::Flags1::FLAG_A.bits;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
error[E0616]: field `bits` of struct `Flags1` is private
|
|
||||||
--> $DIR/private_field.rs:12:41
|
|
||||||
|
|
|
||||||
12 | let flag1 = example::Flags1::FLAG_A.bits;
|
|
||||||
| ^^^^ private field
|
|
||||||
|
|
|
||||||
help: a method `bits` also exists, call it with parentheses
|
|
||||||
|
|
|
||||||
12 | let flag1 = example::Flags1::FLAG_A.bits();
|
|
||||||
| ^^
|
|
@ -1,18 +0,0 @@
|
|||||||
mod example {
|
|
||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
pub struct Flags1: u32 {
|
|
||||||
const FLAG_A = 0b00000001;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Flags2: u32 {
|
|
||||||
const FLAG_B = 0b00000010;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let flag1 = example::Flags1::FLAG_A;
|
|
||||||
let flag2 = example::Flags2::FLAG_B;
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
error[E0603]: struct `Flags2` is private
|
|
||||||
--> $DIR/private_flags.rs:17:26
|
|
||||||
|
|
|
||||||
17 | let flag2 = example::Flags2::FLAG_B;
|
|
||||||
| ^^^^^^ private struct
|
|
||||||
|
|
|
||||||
note: the struct `Flags2` is defined here
|
|
||||||
--> $DIR/private_flags.rs:4:5
|
|
||||||
|
|
|
||||||
4 | / bitflags! {
|
|
||||||
5 | | pub struct Flags1: u32 {
|
|
||||||
6 | | const FLAG_A = 0b00000001;
|
|
||||||
7 | | }
|
|
||||||
... |
|
|
||||||
11 | | }
|
|
||||||
12 | | }
|
|
||||||
| |_____^
|
|
||||||
= note: this error originates in the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
@ -1,9 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
pub struct Flags1: u32 {
|
|
||||||
pub const FLAG_A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,5 +0,0 @@
|
|||||||
error: no rules expected the token `pub`
|
|
||||||
--> $DIR/pub_const.rs:5:9
|
|
||||||
|
|
|
||||||
5 | pub const FLAG_A = 0b00000001;
|
|
||||||
| ^^^ no rules expected this token in macro call
|
|
@ -1,17 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<u32> for Flags {
|
|
||||||
fn from(v: u32) -> Flags {
|
|
||||||
Flags::from_bits_truncate(v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
#[derive(Default)]
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,15 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Flags {
|
|
||||||
pub fn new() -> Flags {
|
|
||||||
Flags::A
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,14 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
// Checks for possible errors caused by overriding names used by `bitflags!` internally.
|
|
||||||
|
|
||||||
mod core {}
|
|
||||||
mod _core {}
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Test: u8 {
|
|
||||||
const A = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,19 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
// Checks for possible errors caused by overriding names used by `bitflags!` internally.
|
|
||||||
|
|
||||||
#[allow(unused_macros)]
|
|
||||||
macro_rules! stringify {
|
|
||||||
($($t:tt)*) => { "..." };
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
struct Test: u8 {
|
|
||||||
const A = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
// Just make sure we don't call the redefined `stringify` macro
|
|
||||||
assert_eq!(format!("{:?}", Test::A), "A");
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
#[repr(C)]
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,10 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
#[repr(transparent)]
|
|
||||||
struct Flags: u32 {
|
|
||||||
const A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
@ -1,11 +0,0 @@
|
|||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
pub struct Flags1: u32 {
|
|
||||||
const FLAG_A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert_eq!(0b00000001, Flags1::FLAG_A.bits);
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
mod a {
|
|
||||||
mod b {
|
|
||||||
use bitflags::bitflags;
|
|
||||||
|
|
||||||
bitflags! {
|
|
||||||
pub(in crate::a) struct Flags: u32 {
|
|
||||||
const FLAG_A = 0b00000001;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn flags() -> u32 {
|
|
||||||
b::Flags::FLAG_A.bits()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert_eq!(0b00000001, a::flags());
|
|
||||||
}
|
|
63
third_party/rust/bitflags/tests/compile.rs
vendored
63
third_party/rust/bitflags/tests/compile.rs
vendored
@ -1,63 +0,0 @@
|
|||||||
use std::{
|
|
||||||
fs,
|
|
||||||
ffi::OsStr,
|
|
||||||
io,
|
|
||||||
path::Path,
|
|
||||||
};
|
|
||||||
|
|
||||||
use walkdir::WalkDir;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn fail() {
|
|
||||||
prepare_stderr_files("tests/compile-fail").unwrap();
|
|
||||||
|
|
||||||
let t = trybuild::TestCases::new();
|
|
||||||
t.compile_fail("tests/compile-fail/**/*.rs");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn pass() {
|
|
||||||
let t = trybuild::TestCases::new();
|
|
||||||
t.pass("tests/compile-pass/**/*.rs");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compiler messages may change between versions
|
|
||||||
// We don't want to have to track these too closely for `bitflags`, but
|
|
||||||
// having some message to check makes sure user-facing errors are sensical.
|
|
||||||
//
|
|
||||||
// The approach we use is to run the test on all compilers, but only check stderr
|
|
||||||
// output on beta (which is the next stable release). We do this by default ignoring
|
|
||||||
// any `.stderr` files in the `compile-fail` directory, and copying `.stderr.beta` files
|
|
||||||
// when we happen to be running on a beta compiler.
|
|
||||||
fn prepare_stderr_files(path: impl AsRef<Path>) -> io::Result<()> {
|
|
||||||
for entry in WalkDir::new(path) {
|
|
||||||
let entry = entry?;
|
|
||||||
|
|
||||||
if entry.path().extension().and_then(OsStr::to_str) == Some("beta") {
|
|
||||||
let renamed = entry.path().with_extension("");
|
|
||||||
|
|
||||||
// Unconditionally remove a corresponding `.stderr` file for a `.stderr.beta`
|
|
||||||
// file if it exists. On `beta` compilers, we'll recreate it. On other compilers,
|
|
||||||
// we don't want to end up checking it anyways.
|
|
||||||
if renamed.exists() {
|
|
||||||
fs::remove_file(&renamed)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
rename_beta_stderr(entry.path(), renamed)?;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rustversion::beta]
|
|
||||||
fn rename_beta_stderr(from: impl AsRef<Path>, to: impl AsRef<Path>) -> io::Result<()> {
|
|
||||||
fs::copy(from, to)?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[rustversion::not(beta)]
|
|
||||||
fn rename_beta_stderr(_: impl AsRef<Path>, _: impl AsRef<Path>) -> io::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user