Skip to content

Commit fb023e5

Browse files
authored
feat: add copy_contents_uninit to ArrayBufferView (#1872)
add copy_contents_uninit
1 parent 98fc2ba commit fb023e5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/array_buffer_view.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::scope::PinScope;
88
use crate::support::int;
99
use std::convert::TryInto;
1010
use std::ffi::c_void;
11+
use std::mem::MaybeUninit;
1112

1213
unsafe extern "C" {
1314
fn v8__ArrayBufferView__Buffer(
@@ -93,6 +94,21 @@ impl ArrayBufferView {
9394
}
9495
}
9596

97+
/// Copy the contents of the ArrayBufferView's buffer to an embedder defined
98+
/// memory without additional overhead that calling ArrayBufferView::Buffer
99+
/// might incur.
100+
/// Returns the number of bytes actually written.
101+
#[inline(always)]
102+
pub fn copy_contents_uninit(&self, dest: &mut [MaybeUninit<u8>]) -> usize {
103+
unsafe {
104+
v8__ArrayBufferView__CopyContents(
105+
self,
106+
dest.as_mut_ptr() as *mut c_void,
107+
dest.len().try_into().unwrap(),
108+
)
109+
}
110+
}
111+
96112
/// Returns the contents of the ArrayBufferView's buffer as a MemorySpan. If
97113
/// the contents are on the V8 heap, they get copied into `storage`. Otherwise
98114
/// a view into the off-heap backing store is returned. The provided storage

0 commit comments

Comments
 (0)