Skip to content

Commit 811eccd

Browse files
authored
Reduce noise in Debug impl of RuntimeVariableList (#8007)
The default debug output of these types contains a lot of unnecessary noise making it hard to read. This PR removes the type and extra fields from debug output to make logs easier to read. `len` could be potentially useful in some cases, but this gives us flexibility to only log it separately if we need it. Related PR in `ssz_types`: - sigp/ssz_types#57 Co-Authored-By: Jimmy Chen <[email protected]>
1 parent 8a4f6cf commit 811eccd

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

consensus/types/src/runtime_fixed_vector.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,21 @@
22
//!
33
//! The length of the list cannot be changed once it is set.
44
5-
#[derive(Clone, Debug)]
5+
use std::fmt;
6+
use std::fmt::Debug;
7+
8+
#[derive(Clone)]
69
pub struct RuntimeFixedVector<T> {
710
vec: Vec<T>,
811
len: usize,
912
}
1013

14+
impl<T: Debug> Debug for RuntimeFixedVector<T> {
15+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
16+
write!(f, "{:?} (len={})", self.vec, self.len)
17+
}
18+
}
19+
1120
impl<T: Clone + Default> RuntimeFixedVector<T> {
1221
pub fn new(vec: Vec<T>) -> Self {
1322
let len = vec.len();

consensus/types/src/runtime_var_list.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use serde::de::Error as DeError;
44
use serde::{Deserialize, Deserializer, Serialize};
55
use ssz::Decode;
66
use ssz_types::Error;
7+
use std::fmt;
8+
use std::fmt::Debug;
79
use std::ops::{Deref, Index, IndexMut};
810
use std::slice::SliceIndex;
911
use tree_hash::{Hash256, MerkleHasher, PackedEncoding, TreeHash, TreeHashType};
@@ -42,7 +44,7 @@ use tree_hash::{Hash256, MerkleHasher, PackedEncoding, TreeHash, TreeHashType};
4244
/// assert!(long.push(6).is_err());
4345
///
4446
/// ```
45-
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
47+
#[derive(Clone, Serialize, Deserialize, Derivative)]
4648
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
4749
#[serde(transparent)]
4850
pub struct RuntimeVariableList<T> {
@@ -51,6 +53,12 @@ pub struct RuntimeVariableList<T> {
5153
max_len: usize,
5254
}
5355

56+
impl<T: Debug> Debug for RuntimeVariableList<T> {
57+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
58+
write!(f, "{:?} (max_len={})", self.vec, self.max_len)
59+
}
60+
}
61+
5462
impl<T> RuntimeVariableList<T> {
5563
/// Returns `Ok` if the given `vec` equals the fixed length of `Self`. Otherwise returns
5664
/// `Err(OutOfBounds { .. })`.

0 commit comments

Comments
 (0)