File: double_borrow.rs

package info (click to toggle)
rust-munge 0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 168 kB
  • sloc: makefile: 2
file content (22 lines) | stat: -rw-r--r-- 445 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
use core::mem::MaybeUninit;
use munge::munge;

fn main() {
    struct Example {
        a: u32,
        b: u32,
    }

    let mut mu = MaybeUninit::<Example>::uninit();

    munge!(let Example { a: a1, b: b1 } = &mut mu);
    assert_eq!(a1.write(1), &1);
    assert_eq!(b1.write(2), &2);

    munge!(let Example { a: a2, b: b2 } = &mut mu);
    assert_eq!(a1.write(3), &3);
    assert_eq!(b1.write(4), &4);

    a2.write(5);
    b2.write(6);
}