diff options
author | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-01-08 00:21:28 +0300 |
commit | 1b6a04ca5504955c571d1c97504fb45ea0befee4 (patch) | |
tree | 7579f518b23313e8a9748a88ab6173d5e030b227 /vendor/rustix/src/bitcast.rs | |
parent | 5ecd8cf2cba827454317368b68571df0d13d7842 (diff) | |
download | fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.tar.xz fparkan-1b6a04ca5504955c571d1c97504fb45ea0befee4.zip |
Initial vendor packages
Signed-off-by: Valentin Popov <valentin@popov.link>
Diffstat (limited to 'vendor/rustix/src/bitcast.rs')
-rw-r--r-- | vendor/rustix/src/bitcast.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/rustix/src/bitcast.rs b/vendor/rustix/src/bitcast.rs new file mode 100644 index 0000000..77e0e63 --- /dev/null +++ b/vendor/rustix/src/bitcast.rs @@ -0,0 +1,34 @@ +//! 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. + // SAFETY: This code is under an `if false`. + #[allow(unsafe_code, unused_unsafe, clippy::useless_transmute)] + 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()) + }}; +} |