mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Rollup merge of #33032 - kindlychung:patch-3, r=Manishearth
Update casting-between-types.md
This commit is contained in:
commit
43c23e5eba
@ -165,10 +165,15 @@ Rust lets us:
|
||||
```rust
|
||||
use std::mem;
|
||||
|
||||
unsafe {
|
||||
let a = [0u8, 0u8, 0u8, 0u8];
|
||||
|
||||
let b = mem::transmute::<[u8; 4], u32>(a);
|
||||
fn main() {
|
||||
unsafe {
|
||||
let a = [0u8, 1u8, 0u8, 0u8];
|
||||
let b = mem::transmute::<[u8; 4], u32>(a);
|
||||
println!("{}", b); // 256
|
||||
// or, more concisely:
|
||||
let c: u32 = mem::transmute(a);
|
||||
println!("{}", c); // 256
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user