diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-02 18:36:06 -0600 |
| commit | 8cdfa445d6629ffef4cb84967ff7017654045bc2 (patch) | |
| tree | 22f0b0907c024c78d26a731e2e1f5219407d8102 /vendor/rustix/src/bitcast.rs | |
| parent | 4351c74c7c5f97156bc94d3a8549b9940ac80e3f (diff) | |
chore: add vendor directory
Diffstat (limited to 'vendor/rustix/src/bitcast.rs')
| -rw-r--r-- | vendor/rustix/src/bitcast.rs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/vendor/rustix/src/bitcast.rs b/vendor/rustix/src/bitcast.rs new file mode 100644 index 00000000..db17c7cb --- /dev/null +++ b/vendor/rustix/src/bitcast.rs @@ -0,0 +1,39 @@ +//! The `bitcast` and `bitflags_bits` macros. + +#![allow(unused_macros)] + +// Ensure that the source and destination types are both primitive integer +// types and the same size, and then bitcast. +macro_rules! bitcast { + ($x:expr) => {{ + if false { + // Ensure the source and destinations are primitive integer types. + let _ = !$x; + let _ = $x as u8; + 0 + } else if false { + // Ensure that the source and destinations are the same size. + #[allow( + unsafe_code, + unused_unsafe, + clippy::useless_transmute, + clippy::missing_transmute_annotations + )] + // SAFETY: This code is under an `if false`. + unsafe { + ::core::mem::transmute($x) + } + } else { + // Do the conversion. + $x as _ + } + }}; +} + +/// Return a [`bitcast`] of the value of `$x.bits()`, where `$x` is a +/// `bitflags` type. +macro_rules! bitflags_bits { + ($x:expr) => {{ + bitcast!($x.bits()) + }}; +} |
