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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//! Message reception buffers that can either contain a borrowed slice or own a memory allocation,
//! with customizable growth behavior, including memory quotas.
//!
//! See [`MsgBuf`]'s documentation.
// TODO fallible allocation
pub use ;
use ;
type MuU8 = ;
/// A message reception buffer that can either contain a borrowed slice or own a memory allocation,
/// with customizable growth behavior, including memory quotas.
///
/// This type can be created from a buffer that lives on the stack:
/// ```
/// # use {core::mem::MaybeUninit, recvmsg::MsgBuf};
/// // An uninitialized buffer:
/// let mut arr = [MaybeUninit::new(0); 32];
/// let buf = MsgBuf::from(arr.as_mut());
/// assert_eq!(buf.capacity(), 32);
/// assert_eq!(buf.init_part().len(), 0); // Assumes nothing about the buffer.
/// assert_eq!(buf.filled_part().len(), 0);
/// assert!(!buf.has_msg); // No message is contained.
///
/// // A fully initialized buffer:
/// let mut arr = [0; 32];
/// let buf = MsgBuf::from(arr.as_mut());
/// assert_eq!(buf.capacity(), 32);
/// // Whole buffer can be passed to methods that take &mut [u8]:
/// assert_eq!(buf.init_part().len(), 32);
/// // Whole buffer is not assumed to be filled:
/// assert_eq!(buf.filled_part().len(), 0);
/// assert!(!buf.has_msg); // Not assumed to already contain a single received message.
/// ```
///
/// Or one on the heap via [`Box`]:
/// ```
/// # extern crate alloc;
/// # use {alloc::boxed::Box, core::mem::MaybeUninit, recvmsg::MsgBuf};
/// // An uninitialized buffer (yes, the annotations are necessary):
/// let buf = MsgBuf::from(Box::<[MaybeUninit<_>]>::from([MaybeUninit::new(0); 32]));
/// assert_eq!(buf.capacity(), 32);
/// assert_eq!(buf.len_init(), 0);
/// assert_eq!(buf.len_filled(), 0);
/// assert!(!buf.has_msg);
///
/// // A fully initialized buffer:
/// let buf = MsgBuf::from(Box::<[u8]>::from([0; 32]));
/// assert_eq!(buf.capacity(), 32);
/// assert_eq!(buf.len_init(), 32);
/// assert_eq!(buf.len_filled(), 0);
/// assert!(!buf.has_msg);
/// ```
///
/// Or in a `Vec`:
/// ```
/// # extern crate alloc;
/// # use {alloc::vec::Vec, core::mem::MaybeUninit, recvmsg::MsgBuf};
/// // An uninitialized buffer:
/// let buf = MsgBuf::from(Vec::with_capacity(31)); // Size can be odd too!
/// assert_eq!(buf.capacity(), 31);
/// assert_eq!(buf.len_init(), 0);
/// assert_eq!(buf.len_filled(), 0);
/// assert!(!buf.has_msg);
///
/// // A partially initialized buffer:
/// let mut vec = Vec::with_capacity(32);
/// vec.resize(6, 0);
/// let buf = MsgBuf::from(vec);
/// assert_eq!(buf.capacity(), 32);
/// assert_eq!(buf.len_init(), 6);
/// assert_eq!(buf.len_filled(), 0);
/// assert!(!buf.has_msg);
/// ```
// Who else remembers that this trait is a thing?
unsafe
unsafe
/// Base pointer getters.