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`:
- https://github.com/sigp/ssz_types/pull/57


  


Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
Jimmy Chen
2025-09-10 14:59:22 +10:00
committed by GitHub
parent 8a4f6cf0d5
commit 811eccdf34
2 changed files with 19 additions and 2 deletions

View File

@@ -2,12 +2,21 @@
//!
//! The length of the list cannot be changed once it is set.
#[derive(Clone, Debug)]
use std::fmt;
use std::fmt::Debug;
#[derive(Clone)]
pub struct RuntimeFixedVector<T> {
vec: Vec<T>,
len: usize,
}
impl<T: Debug> Debug for RuntimeFixedVector<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?} (len={})", self.vec, self.len)
}
}
impl<T: Clone + Default> RuntimeFixedVector<T> {
pub fn new(vec: Vec<T>) -> Self {
let len = vec.len();

View File

@@ -4,6 +4,8 @@ use serde::de::Error as DeError;
use serde::{Deserialize, Deserializer, Serialize};
use ssz::Decode;
use ssz_types::Error;
use std::fmt;
use std::fmt::Debug;
use std::ops::{Deref, Index, IndexMut};
use std::slice::SliceIndex;
use tree_hash::{Hash256, MerkleHasher, PackedEncoding, TreeHash, TreeHashType};
@@ -42,7 +44,7 @@ use tree_hash::{Hash256, MerkleHasher, PackedEncoding, TreeHash, TreeHashType};
/// assert!(long.push(6).is_err());
///
/// ```
#[derive(Debug, Clone, Serialize, Deserialize, Derivative)]
#[derive(Clone, Serialize, Deserialize, Derivative)]
#[derivative(PartialEq, Eq, Hash(bound = "T: std::hash::Hash"))]
#[serde(transparent)]
pub struct RuntimeVariableList<T> {
@@ -51,6 +53,12 @@ pub struct RuntimeVariableList<T> {
max_len: usize,
}
impl<T: Debug> Debug for RuntimeVariableList<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?} (max_len={})", self.vec, self.max_len)
}
}
impl<T> RuntimeVariableList<T> {
/// Returns `Ok` if the given `vec` equals the fixed length of `Self`. Otherwise returns
/// `Err(OutOfBounds { .. })`.