Change JValue::format to take &self instead of self.

This commit is contained in:
jcamiel 2023-11-27 16:51:17 +01:00
parent fcf18aa593
commit 597127f568
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC

View File

@ -33,16 +33,16 @@ 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}]")
@ -50,7 +50,7 @@ impl JValue {
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}}}")