diff --git a/src/unsafe/unions.md b/src/unsafe/unions.md index f0199756..02f03e0f 100644 --- a/src/unsafe/unions.md +++ b/src/unsafe/unions.md @@ -15,3 +15,14 @@ fn main() { println!("bool: {}", unsafe { u.b }); // Undefined behavior! } ``` + +
+ +Unions are very rarely needed in Rust as you can usually use an enum. They are occasionally needed +for interacting with C library APIs. + +If you just want to reinterpret bytes as a different type, you probably want +[`std::mem::transmute`](https://doc.rust-lang.org/stable/std/mem/fn.transmute.html) or a safe +wrapper such as the [`zerocopy`](https://crates.io/crates/zerocopy) crate. + +