Skip to content

Commit b743e60

Browse files
committed
Add user_data field
Signed-off-by: Nick Cameron <nrc@ncameron.org>
1 parent c021fb0 commit b743e60

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/lib.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ use std::io::{Result, Write};
123123
pub struct OwnedBuf {
124124
data: *mut MaybeUninit<u8>,
125125
dtor: unsafe fn(&mut OwnedBuf),
126+
user_data: *const (),
126127
capacity: usize,
127128
/// The length of `self.data` which is known to be filled.
128129
filled: usize,
@@ -152,13 +153,15 @@ impl OwnedBuf {
152153
pub unsafe fn new(
153154
data: *mut MaybeUninit<u8>,
154155
dtor: unsafe fn(&mut OwnedBuf),
156+
user_data: *const (),
155157
capacity: usize,
156158
filled: usize,
157159
init: usize,
158160
) -> OwnedBuf {
159161
OwnedBuf {
160162
data,
161163
dtor,
164+
user_data,
162165
capacity,
163166
filled,
164167
init,
@@ -172,7 +175,7 @@ impl OwnedBuf {
172175
/// It is only safe to use this method if the buffer was created from a `Vec<u8>`.
173176
#[inline]
174177
pub unsafe fn into_vec(self) -> Vec<u8> {
175-
let (data, _, filled, _, capacity) = self.into_raw_parts();
178+
let (data, _, _, filled, _, capacity) = self.into_raw_parts();
176179
Vec::from_raw_parts(data as *mut u8, filled, capacity)
177180
}
178181

@@ -183,7 +186,7 @@ impl OwnedBuf {
183186
/// It is only safe to use this method if the buffer was created from a `Vec<MaybeUninit<u8>>`.
184187
#[inline]
185188
pub unsafe fn into_maybe_uninit_vec(self) -> Vec<MaybeUninit<u8>> {
186-
let (data, _, filled, _, capacity) = self.into_raw_parts();
189+
let (data, _, _, filled, _, capacity) = self.into_raw_parts();
187190
Vec::from_raw_parts(data, filled, capacity)
188191
}
189192

@@ -299,12 +302,20 @@ impl OwnedBuf {
299302
) -> (
300303
*mut MaybeUninit<u8>,
301304
unsafe fn(&mut OwnedBuf),
305+
*const (),
302306
usize,
303307
usize,
304308
usize,
305309
) {
306310
let this = ManuallyDrop::new(self);
307-
(this.data, this.dtor, this.filled, this.init, this.capacity)
311+
(
312+
this.data,
313+
this.dtor,
314+
this.user_data,
315+
this.filled,
316+
this.init,
317+
this.capacity,
318+
)
308319
}
309320
}
310321

@@ -315,7 +326,7 @@ impl Drop for OwnedBuf {
315326
}
316327

317328
unsafe fn drop_vec(buf: &mut OwnedBuf) {
318-
let (data, _, filled, _, capacity) = unsafe { ptr::read(buf) }.into_raw_parts();
329+
let (data, _, _, filled, _, capacity) = unsafe { ptr::read(buf) }.into_raw_parts();
319330
let _vec = Vec::from_raw_parts(data, filled, capacity);
320331
}
321332

@@ -325,6 +336,7 @@ impl From<Vec<MaybeUninit<u8>>> for OwnedBuf {
325336
OwnedBuf {
326337
data,
327338
dtor: drop_vec,
339+
user_data: ptr::null(),
328340
capacity,
329341
filled: len,
330342
init: len,
@@ -338,6 +350,7 @@ impl From<Vec<u8>> for OwnedBuf {
338350
OwnedBuf {
339351
data: data as *mut MaybeUninit<u8>,
340352
dtor: drop_vec,
353+
user_data: ptr::null(),
341354
capacity,
342355
filled: len,
343356
init: len,

0 commit comments

Comments
 (0)