diff --git a/core/io.rs b/core/io.rs index a02b4b4927..c7a56d942d 100644 --- a/core/io.rs +++ b/core/io.rs @@ -7,7 +7,7 @@ use bytes::Buf; 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] and implements +/// be created from a [JsBuffer], [bytes::Bytes], or [Vec] and implements /// `Deref<[u8]>` and `AsRef<[u8]>`. /// /// The wrapper has the ability to constrain the exposed view to a sub-region of @@ -22,7 +22,7 @@ pub struct BufView { enum BufViewInner { Empty, Bytes(bytes::Bytes), - ZeroCopy(JsBuffer), + JsBuffer(JsBuffer), Vec(Vec), } @@ -41,7 +41,7 @@ impl BufView { match &self.inner { BufViewInner::Empty => 0, BufViewInner::Bytes(bytes) => bytes.len() - self.cursor, - BufViewInner::ZeroCopy(zero_copy) => zero_copy.len() - self.cursor, + BufViewInner::JsBuffer(js_buf) => js_buf.len() - self.cursor, BufViewInner::Vec(vec) => vec.len() - self.cursor, } } @@ -87,7 +87,7 @@ impl Deref for BufView { let buf = match &self.inner { BufViewInner::Empty => &[], BufViewInner::Bytes(bytes) => bytes.deref(), - BufViewInner::ZeroCopy(zero_copy) => zero_copy.deref(), + BufViewInner::JsBuffer(js_buf) => js_buf.deref(), BufViewInner::Vec(vec) => vec.deref(), }; &buf[self.cursor..] @@ -102,7 +102,7 @@ impl AsRef<[u8]> for BufView { impl From for BufView { fn from(buf: JsBuffer) -> Self { - Self::from_inner(BufViewInner::ZeroCopy(buf)) + Self::from_inner(BufViewInner::JsBuffer(buf)) } } @@ -123,14 +123,14 @@ impl From for bytes::Bytes { match buf.inner { BufViewInner::Empty => bytes::Bytes::new(), BufViewInner::Bytes(bytes) => bytes, - BufViewInner::ZeroCopy(zero_copy) => zero_copy.into(), + BufViewInner::JsBuffer(js_buf) => js_buf.into(), BufViewInner::Vec(vec) => vec.into(), } } } /// BufMutView is a wrapper around an underlying contiguous chunk of writable -/// bytes. It can be created from a `ZeroCopyBuf` or a `Vec` and implements +/// bytes. It can be created from a `JsBuffer` or a `Vec` and implements /// `DerefMut<[u8]>` and `AsMut<[u8]>`. /// /// The wrapper has the ability to constrain the exposed view to a sub-region of @@ -145,7 +145,7 @@ pub struct BufMutView { } enum BufMutViewInner { - ZeroCopy(JsBuffer), + JsBuffer(JsBuffer), Vec(Vec), } @@ -162,7 +162,7 @@ impl BufMutView { /// buffer minus the cursor position. pub fn len(&self) -> usize { match &self.inner { - BufMutViewInner::ZeroCopy(zero_copy) => zero_copy.len() - self.cursor, + BufMutViewInner::JsBuffer(js_buf) => js_buf.len() - self.cursor, BufMutViewInner::Vec(vec) => vec.len() - self.cursor, } } @@ -189,7 +189,7 @@ impl BufMutView { /// Turn this `BufMutView` into a `BufView`. pub fn into_view(self) -> BufView { let inner = match self.inner { - BufMutViewInner::ZeroCopy(zero_copy) => BufViewInner::ZeroCopy(zero_copy), + BufMutViewInner::JsBuffer(js_buf) => BufViewInner::JsBuffer(js_buf), BufMutViewInner::Vec(vec) => BufViewInner::Vec(vec), }; BufView { @@ -201,11 +201,11 @@ impl BufMutView { /// Unwrap the underlying buffer into a `Vec`, consuming the `BufMutView`. /// /// This method panics when called on a `BufMutView` that was created from a - /// `ZeroCopyBuf`. + /// `JsBuffer`. pub fn unwrap_vec(self) -> Vec { match self.inner { - BufMutViewInner::ZeroCopy(_) => { - panic!("Cannot unwrap a ZeroCopyBuf backed BufMutView into a Vec"); + BufMutViewInner::JsBuffer(_) => { + panic!("Cannot unwrap a JsBuffer backed BufMutView into a Vec"); } BufMutViewInner::Vec(vec) => vec, } @@ -214,11 +214,11 @@ impl BufMutView { /// Get a mutable reference to an underlying `Vec`. /// /// This method panics when called on a `BufMutView` that was created from a - /// `ZeroCopyBuf`. + /// `JsBuffer`. pub fn get_mut_vec(&mut self) -> &mut Vec { match &mut self.inner { - BufMutViewInner::ZeroCopy(_) => { - panic!("Cannot unwrap a ZeroCopyBuf backed BufMutView into a Vec"); + BufMutViewInner::JsBuffer(_) => { + panic!("Cannot unwrap a JsBuffer backed BufMutView into a Vec"); } BufMutViewInner::Vec(vec) => vec, } @@ -244,7 +244,7 @@ impl Deref for BufMutView { fn deref(&self) -> &[u8] { let buf = match &self.inner { - BufMutViewInner::ZeroCopy(zero_copy) => zero_copy.deref(), + BufMutViewInner::JsBuffer(js_buf) => js_buf.deref(), BufMutViewInner::Vec(vec) => vec.deref(), }; &buf[self.cursor..] @@ -254,7 +254,7 @@ impl Deref for BufMutView { impl DerefMut for BufMutView { fn deref_mut(&mut self) -> &mut [u8] { let buf = match &mut self.inner { - BufMutViewInner::ZeroCopy(zero_copy) => zero_copy.deref_mut(), + BufMutViewInner::JsBuffer(js_buf) => js_buf.deref_mut(), BufMutViewInner::Vec(vec) => vec.deref_mut(), }; &mut buf[self.cursor..] @@ -275,7 +275,7 @@ impl AsMut<[u8]> for BufMutView { impl From for BufMutView { fn from(buf: JsBuffer) -> Self { - Self::from_inner(BufMutViewInner::ZeroCopy(buf)) + Self::from_inner(BufMutViewInner::JsBuffer(buf)) } } diff --git a/serde_v8/tests/magic.rs b/serde_v8/tests/magic.rs index 09e5205616..e3ed1d330d 100644 --- a/serde_v8/tests/magic.rs +++ b/serde_v8/tests/magic.rs @@ -130,7 +130,7 @@ fn magic_buffer() { let eq = js_exec(scope, "t3.b[4] === 11"); assert!(eq.is_true()); - // ZeroCopyBuf as bytes::Bytes + // JsBuffer as bytes::Bytes let v8_array = js_exec(scope, "new Uint8Array([1,2,3,4,5])"); let zbuf: serde_v8::JsBuffer = serde_v8::from_v8(scope, v8_array).unwrap(); let buf: bytes::Bytes = zbuf.into();