1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
use fmt;
use ;
use slice;
use crateRawBufMut;
use crateZeroCopy;
/// A value which might or might not have been initialized.
///
/// This differs from the standard library
/// [`MaybeUninit`][core::mem::MaybeUninit] in that its methods does not assume
/// that the value is aligned.
///
/// # Examples
///
/// Writing to a pre-allocation location in an [`AlignedBuf`].
///
/// [`AlignedBuf`]: crate::buf::AlignedBuf
///
/// ```
/// use musli_zerocopy::{AlignedBuf, ZeroCopy};
/// use musli_zerocopy::mem::MaybeUninit;
/// use musli_zerocopy::pointer::{Ref, Unsized};
///
/// #[derive(ZeroCopy)]
/// #[repr(C)]
/// struct Custom { string: Unsized<str> }
///
/// let mut buf = AlignedBuf::new();
///
/// let reference: Ref<MaybeUninit<Custom>> = buf.store_uninit::<Custom>();
///
/// let string = buf.store_unsized("Hello World!");
///
/// buf.load_uninit_mut(reference).write(&Custom { string });
///
/// let buf = buf.as_aligned();
/// let reference = reference.assume_init();
///
/// assert_eq!(reference.offset(), 0);
///
/// let custom = buf.load(reference)?;
/// assert_eq!(buf.load(custom.string)?, "Hello World!");
/// # Ok::<_, musli_zerocopy::Error>(())
/// ```
pub union