Skip to content

Commit

Permalink
Impl more readable 'Debug' for 'Value'.
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed May 17, 2024
1 parent 4bb7876 commit 2f4ef2c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/value/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub type Dict = Map<String, Value>;
/// 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),
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2f4ef2c

Please sign in to comment.