summaryrefslogtreecommitdiff
path: root/serde_v8/magic/bytestring.rs
diff options
context:
space:
mode:
Diffstat (limited to 'serde_v8/magic/bytestring.rs')
-rw-r--r--serde_v8/magic/bytestring.rs80
1 files changed, 3 insertions, 77 deletions
diff --git a/serde_v8/magic/bytestring.rs b/serde_v8/magic/bytestring.rs
index 43ac54b97..a4c664b29 100644
--- a/serde_v8/magic/bytestring.rs
+++ b/serde_v8/magic/bytestring.rs
@@ -1,85 +1,11 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
-
-use std::ops::{Deref, DerefMut};
-
use super::transl8::{FromV8, ToV8};
-use crate::magic::transl8::impl_magic;
+use crate::magic::transl8::{impl_magic, impl_wrapper};
use crate::Error;
-#[derive(PartialEq, Eq, Clone, Debug)]
-pub struct ByteString(pub Vec<u8>);
+impl_wrapper! { pub struct ByteString(Vec<u8>); }
impl_magic!(ByteString);
-impl ByteString {
- pub fn new() -> ByteString {
- ByteString(Vec::new())
- }
-
- pub fn with_capacity(capacity: usize) -> ByteString {
- ByteString(Vec::with_capacity(capacity))
- }
-
- pub fn capacity(&self) -> usize {
- self.0.capacity()
- }
-
- pub fn reserve(&mut self, additional: usize) {
- self.0.reserve(additional)
- }
-
- pub fn reserve_exact(&mut self, additional: usize) {
- self.0.reserve_exact(additional)
- }
-
- pub fn shrink_to_fit(&mut self) {
- self.0.shrink_to_fit()
- }
-
- pub fn truncate(&mut self, len: usize) {
- self.0.truncate(len)
- }
-
- pub fn push(&mut self, value: u8) {
- self.0.push(value)
- }
-
- pub fn pop(&mut self) -> Option<u8> {
- self.0.pop()
- }
-}
-
-impl Default for ByteString {
- fn default() -> Self {
- ByteString::new()
- }
-}
-
-impl Deref for ByteString {
- type Target = [u8];
-
- fn deref(&self) -> &[u8] {
- self.0.deref()
- }
-}
-
-impl DerefMut for ByteString {
- fn deref_mut(&mut self) -> &mut [u8] {
- self.0.deref_mut()
- }
-}
-
-impl AsRef<[u8]> for ByteString {
- fn as_ref(&self) -> &[u8] {
- self.0.as_ref()
- }
-}
-
-impl AsMut<[u8]> for ByteString {
- fn as_mut(&mut self) -> &mut [u8] {
- self.0.as_mut()
- }
-}
-
impl ToV8 for ByteString {
fn to_v8<'a>(
&self,
@@ -117,6 +43,6 @@ impl FromV8 for ByteString {
);
assert!(written == len);
}
- Ok(ByteString(buffer))
+ Ok(buffer.into())
}
}