Repository: denoland/deno_core (rust)

Issue:
Consider removing derive_more dependency for serde_v8
This dependency is only used to derive trivial `Deref`, `DerefMut`, `AsRef` and `AsMut` implementations. However, it requires 3.3s to compile on my machine and much more if you count all its dependencies.

Would you accept a PR that replaces these derives with hand-written (or `macro_rules!`-produced) implementations?

Related: https://github.com/denoland/rust-urlpattern/issues/47

Pull request description:
Replace usage of derive_more derives with manual implementations
I found some of the generated impls like [this one](https://docs.rs/serde_v8/latest/serde_v8/struct.BigInt.html#impl-AsMut%3C__AsMutT%3E-for-BigInt) quite weird so I removed or replaced them with different ones, as seemed reasonable in the specific cases.

Let me know what you think. The individual commit messages have more details on why I chose certain replacements.

Closes #640.

Patch:
diff --git a/Cargo.lock b/Cargo.lock
index eebee92..75deaca 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -105,7 +105,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -297,12 +297,6 @@ version = "1.0.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
 
-[[package]]
-name = "convert_case"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e"
-
 [[package]]
 name = "cooked-waker"
 version = "5.0.0"
@@ -563,7 +557,7 @@ dependencies = [
  "quote",
  "strum",
  "strum_macros",
- "syn 2.0.48",
+ "syn",
  "testing_macros",
  "thiserror",
 ]
@@ -579,7 +573,7 @@ dependencies = [
  "prettyplease",
  "rustversion",
  "serde",
- "syn 2.0.48",
+ "syn",
  "testing_macros",
  "trybuild",
 ]
@@ -593,19 +587,6 @@ dependencies = [
  "tokio",
 ]
 
-[[package]]
-name = "derive_more"
-version = "0.99.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
-dependencies = [
- "convert_case",
- "proc-macro2",
- "quote",
- "rustc_version 0.4.0",
- "syn 1.0.109",
-]
-
 [[package]]
 name = "diff"
 version = "0.1.13"
@@ -708,7 +689,7 @@ checksum = "3a0b11eeb173ce52f84ebd943d42e58813a2ebb78a6a3ff0a243b71c5199cd7b"
 dependencies = [
  "proc-macro2",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -777,7 +758,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1037,7 +1018,7 @@ dependencies = [
  "Inflector",
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1278,7 +1259,7 @@ dependencies = [
  "phf_shared",
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1307,7 +1288,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1358,7 +1339,7 @@ checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1384,7 +1365,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5"
 dependencies = [
  "proc-macro2",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1395,7 +1376,7 @@ checksum = "07c277e4e643ef00c1233393c673f655e3672cf7eb3ba08a00bdd0ea59139b5f"
 dependencies = [
  "proc-macro-rules-macros",
  "proc-macro2",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1407,7 +1388,7 @@ dependencies = [
  "once_cell",
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1556,7 +1537,7 @@ dependencies = [
  "regex",
  "relative-path",
  "rustc_version 0.4.0",
- "syn 2.0.48",
+ "syn",
  "unicode-ident",
 ]
 
@@ -1689,7 +1670,7 @@ checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1710,7 +1691,6 @@ version = "0.178.0"
 dependencies = [
  "bencher",
  "bytes",
- "derive_more",
  "num-bigint",
  "serde",
  "serde_bytes",
@@ -1867,7 +1847,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1895,7 +1875,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "rustversion",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -1957,7 +1937,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2006,7 +1986,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2090,7 +2070,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2194,7 +2174,7 @@ checksum = "695a1d8b461033d32429b5befbf0ad4d7a2c4d6ba9cd5ba4e0645c615839e8e4"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2205,7 +2185,7 @@ checksum = "50176cfc1cbc8bb22f41c6fe9d1ec53fbe057001219b5954961b8ad0f336fce9"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2229,18 +2209,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "swc_macros_common",
- "syn 2.0.48",
-]
-
-[[package]]
-name = "syn"
-version = "1.0.109"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
+ "syn",
 ]
 
 [[package]]
@@ -2276,7 +2245,7 @@ dependencies = [
  "quote",
  "regex",
  "relative-path",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2305,7 +2274,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2360,7 +2329,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2396,7 +2365,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
 ]
 
 [[package]]
@@ -2590,7 +2559,7 @@ dependencies = [
  "once_cell",
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
  "wasm-bindgen-shared",
 ]
 
@@ -2612,7 +2581,7 @@ checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.48",
+ "syn",
  "wasm-bindgen-backend",
  "wasm-bindgen-shared",
 ]
diff --git a/Cargo.toml b/Cargo.toml
index c4bde4d..ccaa57f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -36,7 +36,6 @@ bit-set = "0"
 bit-vec = "0"
 bytes = "1.4.0"
 cooked-waker = "5"
-derive_more = "0.99.17"
 fastrand = "2"
 futures = "0.3.21"
 libc = "0.2.126"
diff --git a/serde_v8/Cargo.toml b/serde_v8/Cargo.toml
index 9d8cae0..f5dcfdb 100644
--- a/serde_v8/Cargo.toml
+++ b/serde_v8/Cargo.toml
@@ -15,7 +15,6 @@ path = "lib.rs"
 
 [dependencies]
 bytes.workspace = true
-derive_more.workspace = true
 num-bigint.workspace = true
 serde.workspace = true
 smallvec = { workspace = true, features = ["union"] }
diff --git a/serde_v8/magic/bigint.rs b/serde_v8/magic/bigint.rs
index 3391b1a..6405f56 100644
--- a/serde_v8/magic/bigint.rs
+++ b/serde_v8/magic/bigint.rs
@@ -1,5 +1,8 @@
 // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
 
+use std::ops::Deref;
+use std::ops::DerefMut;
+
 use smallvec::smallvec;
 use smallvec::SmallVec;
 
@@ -8,22 +11,24 @@ use super::transl8::ToV8;
 use crate::magic::transl8::impl_magic;
 use crate::Error;
 
-#[derive(
-  PartialEq,
-  Eq,
-  Clone,
-  Debug,
-  Default,
-  derive_more::Deref,
-  derive_more::DerefMut,
-  derive_more::AsRef,
-  derive_more::AsMut,
-)]
-#[as_mut(forward)]
-#[as_ref(forward)]
+#[derive(PartialEq, Eq, Clone, Debug, Default)]
 pub struct BigInt(num_bigint::BigInt);
 impl_magic!(BigInt);
 
+impl Deref for BigInt {
+  type Target = num_bigint::BigInt;
+
+  fn deref(&self) -> &Self::Target {
+    &self.0
+  }
+}
+
+impl DerefMut for BigInt {
+  fn deref_mut(&mut self) -> &mut Self::Target {
+    &mut self.0
+  }
+}
+
 impl ToV8 for BigInt {
   fn to_v8<'a>(
     &mut self,
diff --git a/serde_v8/magic/transl8.rs b/serde_v8/magic/transl8.rs
index 5f3f791..7472726 100644
--- a/serde_v8/magic/transl8.rs
+++ b/serde_v8/magic/transl8.rs
@@ -141,25 +141,3 @@ macro_rules! impl_magic {
   };
 }
 pub(crate) use impl_magic;
-
-macro_rules! impl_wrapper {
-  ($i:item) => {
-    #[derive(
-      PartialEq,
-      Eq,
-      Clone,
-      Debug,
-      Default,
-      derive_more::Deref,
-      derive_more::DerefMut,
-      derive_more::AsRef,
-      derive_more::AsMut,
-      derive_more::From,
-    )]
-    #[as_mut(forward)]
-    #[as_ref(forward)]
-    #[from(forward)]
-    $i
-  };
-}
-pub(crate) use impl_wrapper;
diff --git a/serde_v8/magic/u16string.rs b/serde_v8/magic/u16string.rs
index 040207d..b9d74ef 100644
--- a/serde_v8/magic/u16string.rs
+++ b/serde_v8/magic/u16string.rs
@@ -1,17 +1,68 @@
 // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
 
+use std::ops::Deref;
+use std::ops::DerefMut;
+
 use crate::Error;
 
 use super::transl8::impl_magic;
-use super::transl8::impl_wrapper;
 use super::transl8::FromV8;
 use super::transl8::ToV8;
 
-impl_wrapper!(
-  pub struct U16String(Vec<u16>);
-);
+#[derive(PartialEq, Eq, Clone, Debug, Default)]
+pub struct U16String(Vec<u16>);
 impl_magic!(U16String);
 
+impl Deref for U16String {
+  type Target = Vec<u16>;
+
+  fn deref(&self) -> &Self::Target {
+    &self.0
+  }
+}
+
+impl DerefMut for U16String {
+  fn deref_mut(&mut self) -> &mut Self::Target {
+    &mut self.0
+  }
+}
+
+impl AsRef<[u16]> for U16String {
+  fn as_ref(&self) -> &[u16] {
+    &self.0
+  }
+}
+
+impl AsMut<[u16]> for U16String {
+  fn as_mut(&mut self) -> &mut [u16] {
+    &mut self.0
+  }
+}
+
+impl<const N: usize> From<[u16; N]> for U16String {
+  fn from(value: [u16; N]) -> Self {
+    Self(value.into())
+  }
+}
+
+impl<const N: usize> From<&[u16; N]> for U16String {
+  fn from(value: &[u16; N]) -> Self {
+    Self(value.into())
+  }
+}
+
+impl From<&[u16]> for U16String {
+  fn from(value: &[u16]) -> Self {
+    Self(value.into())
+  }
+}
+
+impl From<Vec<u16>> for U16String {
+  fn from(value: Vec<u16>) -> Self {
+    Self(value)
+  }
+}
+
 impl ToV8 for U16String {
   fn to_v8<'a>(
     &mut self,


Test patch:
diff --git a/serde_v8/magic/bytestring.rs b/serde_v8/magic/bytestring.rs
index 5fa776f..671634f 100644
--- a/serde_v8/magic/bytestring.rs
+++ b/serde_v8/magic/bytestring.rs
@@ -1,29 +1,48 @@
 // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
+
+use std::mem::size_of;
+use std::ops::Deref;
+use std::ops::DerefMut;
+
+use smallvec::SmallVec;
+
 use super::transl8::FromV8;
 use super::transl8::ToV8;
 use crate::magic::transl8::impl_magic;
 use crate::Error;
-use smallvec::SmallVec;
-use std::mem::size_of;
 
 const USIZE2X: usize = size_of::<usize>() * 2;
 
-#[derive(
-  PartialEq,
-  Eq,
-  Clone,
-  Debug,
-  Default,
-  derive_more::Deref,
-  derive_more::DerefMut,
-  derive_more::AsRef,
-  derive_more::AsMut,
-)]
-#[as_mut(forward)]
-#[as_ref(forward)]
+#[derive(PartialEq, Eq, Clone, Debug, Default)]
 pub struct ByteString(SmallVec<[u8; USIZE2X]>);
 impl_magic!(ByteString);
 
+impl Deref for ByteString {
+  type Target = SmallVec<[u8; USIZE2X]>;
+
+  fn deref(&self) -> &Self::Target {
+    &self.0
+  }
+}
+
+impl DerefMut for ByteString {
+  fn deref_mut(&mut self) -> &mut Self::Target {
+    &mut self.0
+  }
+}
+
+impl AsRef<[u8]> for ByteString {
+  fn as_ref(&self) -> &[u8] {
+    &self.0
+  }
+}
+
+impl AsMut<[u8]> for ByteString {
+  fn as_mut(&mut self) -> &mut [u8] {
+    &mut self.0
+  }
+}
+
 // const-assert that Vec<u8> and SmallVec<[u8; size_of::<usize>() * 2]> have a same size.
 // Note from https://docs.rs/smallvec/latest/smallvec/#union -
 //   smallvec can still be larger than Vec if the inline buffer is