Skip to content

Commit

Permalink
Implement Debug on the Value
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Dec 10, 2024
1 parent 32a6da2 commit e8d5086
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt;
use std::hash::BuildHasher;

use bumpalo::Bump;
Expand All @@ -8,7 +9,6 @@ use serde::de::Visitor;
use serde_json::value::RawValue;

/// Represents a partially parsed JSON value referencing the underlying data.
#[derive(Debug)]
pub enum Value<'bump, S = DefaultHashBuilder> {
/// A JSON null value.
Null,
Expand Down Expand Up @@ -179,3 +179,17 @@ impl<'de, S: BuildHasher> Visitor<'de> for ValueVisitor<'de, S> {
Ok(Value::Object(object))
}
}

impl<S> fmt::Debug for Value<'_, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("Value::")?;
match self {
Value::Null => f.debug_tuple("Null").finish(),
Value::Bool(boolean) => f.debug_tuple("Bool").field(&boolean).finish(),
Value::Number(number) => f.debug_tuple("Number").field(&number).finish(),
Value::String(string) => f.debug_tuple("String").field(&string).finish(),
Value::Array(array) => f.debug_tuple("Array").field(array).finish(),
Value::Object(object) => f.debug_tuple("Object").field(object).finish(),
}
}
}

0 comments on commit e8d5086

Please sign in to comment.