From 2f4ef2caa73c29edb5ebe99afc40da8d1ee95e1a Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 16 May 2024 19:52:41 -0700 Subject: [PATCH] Impl more readable 'Debug' for 'Value'. --- src/value/value.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/value/value.rs b/src/value/value.rs index 25655cd..9aefbb9 100644 --- a/src/value/value.rs +++ b/src/value/value.rs @@ -23,7 +23,7 @@ pub type Dict = Map; /// let v = Value::from("hello"); /// assert_eq!(v.as_str(), Some("hello")); /// ``` -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum Value { /// A string. String(Tag, String), @@ -421,6 +421,20 @@ impl Value { } } +impl std::fmt::Debug for Value { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::String(_, v) => f.debug_tuple("String").field(v).finish(), + Self::Char(_, v) => f.debug_tuple("Char").field(v).finish(), + Self::Bool(_, v) => f.debug_tuple("Bool").field(v).finish(), + Self::Num(_, v) => f.debug_tuple("Num").field(v).finish(), + Self::Empty(_, v) => f.debug_tuple("Empty").field(v).finish(), + Self::Dict(_, v) => f.debug_tuple("Dict").field(v).finish(), + Self::Array(_, v) => f.debug_tuple("Array").field(v).finish(), + } + } +} + impl PartialEq for Value { fn eq(&self, other: &Self) -> bool { match (self, other) {