summaryrefslogtreecommitdiff
path: root/core/io.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-06-22 23:37:56 +0200
committerGitHub <noreply@github.com>2023-06-22 23:37:56 +0200
commitdda0f1c343bfb3196ce6a7c7e8c2acccfd5c2e5b (patch)
tree10fc273a620949ccf63826363499f8f39056896d /core/io.rs
parentb319fa7f4965af3d3d576ea528248a31c96a4053 (diff)
refactor(serde_v8): split ZeroCopyBuf into JsBuffer and ToJsBuffer (#19566)
`ZeroCopyBuf` was convenient to use, but sometimes it did hide details that some copies were necessary in certain cases. Also it made it way to easy for the caller to pass around and convert into different values. This commit splits `ZeroCopyBuf` into `JsBuffer` (an array buffer coming from V8) and `ToJsBuffer` (a Rust buffer that will be converted into a V8 array buffer). As a result some magical conversions were removed (they were never used) limiting the API surface and preparing for changes in #19534.
Diffstat (limited to 'core/io.rs')
-rw-r--r--core/io.rs14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/io.rs b/core/io.rs
index 567d50bd4..a02b4b492 100644
--- a/core/io.rs
+++ b/core/io.rs
@@ -4,7 +4,7 @@ use std::ops::Deref;
use std::ops::DerefMut;
use bytes::Buf;
-use serde_v8::ZeroCopyBuf;
+use serde_v8::JsBuffer;
/// BufView is a wrapper around an underlying contiguous chunk of bytes. It can
/// be created from a [ZeroCopyBuf], [bytes::Bytes], or [Vec<u8>] and implements
@@ -22,7 +22,7 @@ pub struct BufView {
enum BufViewInner {
Empty,
Bytes(bytes::Bytes),
- ZeroCopy(ZeroCopyBuf),
+ ZeroCopy(JsBuffer),
Vec(Vec<u8>),
}
@@ -100,8 +100,8 @@ impl AsRef<[u8]> for BufView {
}
}
-impl From<ZeroCopyBuf> for BufView {
- fn from(buf: ZeroCopyBuf) -> Self {
+impl From<JsBuffer> for BufView {
+ fn from(buf: JsBuffer) -> Self {
Self::from_inner(BufViewInner::ZeroCopy(buf))
}
}
@@ -145,7 +145,7 @@ pub struct BufMutView {
}
enum BufMutViewInner {
- ZeroCopy(ZeroCopyBuf),
+ ZeroCopy(JsBuffer),
Vec(Vec<u8>),
}
@@ -273,8 +273,8 @@ impl AsMut<[u8]> for BufMutView {
}
}
-impl From<ZeroCopyBuf> for BufMutView {
- fn from(buf: ZeroCopyBuf) -> Self {
+impl From<JsBuffer> for BufMutView {
+ fn from(buf: JsBuffer) -> Self {
Self::from_inner(BufMutViewInner::ZeroCopy(buf))
}
}