diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-06-22 23:37:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-22 23:37:56 +0200 |
commit | dda0f1c343bfb3196ce6a7c7e8c2acccfd5c2e5b (patch) | |
tree | 10fc273a620949ccf63826363499f8f39056896d /serde_v8/serializable.rs | |
parent | b319fa7f4965af3d3d576ea528248a31c96a4053 (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 'serde_v8/serializable.rs')
-rw-r--r-- | serde_v8/serializable.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/serde_v8/serializable.rs b/serde_v8/serializable.rs index b02aa0629..36a8bc27b 100644 --- a/serde_v8/serializable.rs +++ b/serde_v8/serializable.rs @@ -4,8 +4,8 @@ use std::mem::transmute_copy; use crate::BigInt; use crate::ByteString; +use crate::ToJsBuffer; use crate::U16String; -use crate::ZeroCopyBuf; /// Serializable exists to allow boxing values as "objects" to be serialized later, /// this is particularly useful for async op-responses. This trait is a more efficient @@ -63,7 +63,7 @@ pub enum Primitive { Float32(f32), Float64(f64), String(String), - ZeroCopyBuf(ZeroCopyBuf), + RustToV8Buf(ToJsBuffer), ByteString(ByteString), U16String(U16String), BigInt(BigInt), @@ -88,7 +88,7 @@ impl serde::Serialize for Primitive { Self::Float32(x) => x.serialize(s), Self::Float64(x) => x.serialize(s), Self::String(x) => x.serialize(s), - Self::ZeroCopyBuf(x) => x.serialize(s), + Self::RustToV8Buf(x) => x.serialize(s), Self::ByteString(x) => x.serialize(s), Self::U16String(x) => x.serialize(s), Self::BigInt(x) => x.serialize(s), @@ -134,8 +134,8 @@ impl<T: serde::Serialize + 'static> From<T> for SerializablePkg { Self::Primitive(Primitive::Float64(tc(x))) } else if tid == TypeId::of::<String>() { Self::Primitive(Primitive::String(tc(x))) - } else if tid == TypeId::of::<ZeroCopyBuf>() { - Self::Primitive(Primitive::ZeroCopyBuf(tc(x))) + } else if tid == TypeId::of::<ToJsBuffer>() { + Self::Primitive(Primitive::RustToV8Buf(tc(x))) } else if tid == TypeId::of::<ByteString>() { Self::Primitive(Primitive::ByteString(tc(x))) } else if tid == TypeId::of::<U16String>() { |