Skip to content

Commit

Permalink
Change JValue::format to take &self instead of self.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcamiel committed Nov 28, 2023
1 parent fcf18aa commit 597127f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/hurlfmt/src/format/serialize_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ pub enum JValue {
}

impl JValue {
pub fn format(self) -> String {
pub fn format(&self) -> String {
match self {
JValue::Null => "null".to_string(),
JValue::Number(n) => n,
JValue::Number(n) => n.to_string(),
JValue::String(s) => format!("\"{}\"", s.chars().map(format_char).collect::<String>()),
JValue::Boolean(b) => b.to_string(),
JValue::List(elem) => {
let s = elem
.iter()
.map(|e| e.clone().format())
.map(|e| e.format())
.collect::<Vec<String>>()
.join(",");
format!("[{s}]")
}
JValue::Object(key_values) => {
let s = key_values
.iter()
.map(|(k, v)| format!("\"{}\":{}", k, v.clone().format()))
.map(|(k, v)| format!("\"{}\":{}", k, v.format()))
.collect::<Vec<String>>()
.join(",");
format!("{{{s}}}")
Expand Down

0 comments on commit 597127f

Please sign in to comment.