summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/bitcast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/rustix/src/bitcast.rs')
-rw-r--r--vendor/rustix/src/bitcast.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/vendor/rustix/src/bitcast.rs b/vendor/rustix/src/bitcast.rs
new file mode 100644
index 000000000..3924c29d5
--- /dev/null
+++ b/vendor/rustix/src/bitcast.rs
@@ -0,0 +1,32 @@
+// Ensure that the source and destination types are both primitive integer
+// types and the same size, and then bitcast.
+#[allow(unused_macros)]
+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.
+#[allow(unused_macros)]
+macro_rules! bitflags_bits {
+ ($x:expr) => {{
+ bitcast!($x.bits())
+ }};
+}