Skip to content

Commit 44deb75

Browse files
authored
Remove derivative in favour of manual Debug impl (#61)
1 parent dd6ac18 commit 44deb75

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ typenum = "1.12.0"
2020
smallvec = "1.8.0"
2121
arbitrary = { version = "1.0", features = ["derive"], optional = true }
2222
itertools = "0.14.0"
23-
derivative = "2"
2423

2524
[dev-dependencies]
2625
criterion = "0.7.0"

src/fixed_vector.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::tree_hash::vec_tree_hash_root;
22
use crate::Error;
3-
use derivative::Derivative;
43
use serde::Deserialize;
54
use serde_derive::Serialize;
65
use std::marker::PhantomData;
@@ -45,12 +44,10 @@ pub use typenum;
4544
/// let err = FixedVector::<_, typenum::U5>::try_from(base.clone()).unwrap_err();
4645
/// assert_eq!(err, Error::OutOfBounds { i: 4, len: 5 });
4746
/// ```
48-
#[derive(Clone, Serialize, Derivative)]
49-
#[derivative(Debug = "transparent")]
47+
#[derive(Clone, Serialize)]
5048
#[serde(transparent)]
5149
pub struct FixedVector<T, N> {
5250
vec: Vec<T>,
53-
#[derivative(Debug = "ignore")]
5451
_phantom: PhantomData<N>,
5552
}
5653

@@ -67,6 +64,12 @@ impl<T: std::hash::Hash, N> std::hash::Hash for FixedVector<T, N> {
6764
}
6865
}
6966

67+
impl<T: std::fmt::Debug, N> std::fmt::Debug for FixedVector<T, N> {
68+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
69+
self.vec.fmt(f)
70+
}
71+
}
72+
7073
impl<T, N: Unsigned> FixedVector<T, N> {
7174
/// Returns `Ok` if the given `vec` equals the fixed length of `Self`. Otherwise returns
7275
/// `Err`.
@@ -571,4 +574,12 @@ mod test {
571574
let result: Result<FixedVector<u64, U4>, _> = serde_json::from_value(json);
572575
assert!(result.is_ok());
573576
}
577+
578+
#[test]
579+
fn debug_transparent() {
580+
let vec: FixedVector<u64, U4> = FixedVector::try_from(vec![1, 2, 3, 4]).unwrap();
581+
let debug_output = format!("{:?}", vec);
582+
583+
assert_eq!(debug_output, "[1, 2, 3, 4]");
584+
}
574585
}

src/variable_list.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::tree_hash::vec_tree_hash_root;
22
use crate::Error;
3-
use derivative::Derivative;
43
use serde::Deserialize;
54
use serde_derive::Serialize;
65
use std::marker::PhantomData;
@@ -48,12 +47,10 @@ pub use typenum;
4847
/// // Push a value to if it _does_ exceed the maximum.
4948
/// assert!(long.push(6).is_err());
5049
/// ```
51-
#[derive(Clone, Serialize, Derivative)]
52-
#[derivative(Debug = "transparent")]
50+
#[derive(Clone, Serialize)]
5351
#[serde(transparent)]
5452
pub struct VariableList<T, N> {
5553
vec: Vec<T>,
56-
#[derivative(Debug = "ignore")]
5754
_phantom: PhantomData<N>,
5855
}
5956

@@ -70,6 +67,12 @@ impl<T: std::hash::Hash, N> std::hash::Hash for VariableList<T, N> {
7067
}
7168
}
7269

70+
impl<T: std::fmt::Debug, N> std::fmt::Debug for VariableList<T, N> {
71+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
72+
self.vec.fmt(f)
73+
}
74+
}
75+
7376
/// Maximum number of elements to pre-allocate in `try_from_iter`.
7477
///
7578
/// Some variable lists have *very long* maximum lengths such that we can't actually fit them
@@ -631,4 +634,12 @@ mod test {
631634
let result: Result<VariableList<u64, U4>, _> = serde_json::from_value(json);
632635
assert!(result.is_ok());
633636
}
637+
638+
#[test]
639+
fn debug_transparent_list() {
640+
let list: VariableList<u64, U5> = VariableList::try_from(vec![1, 2, 3]).unwrap();
641+
let debug_output = format!("{:?}", list);
642+
643+
assert_eq!(debug_output, "[1, 2, 3]");
644+
}
634645
}

0 commit comments

Comments
 (0)