Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Purpose of internal function wrap_value #47

Open
Imberflur opened this issue Aug 9, 2024 · 0 comments
Open

Purpose of internal function wrap_value #47

Imberflur opened this issue Aug 9, 2024 · 0 comments

Comments

@Imberflur
Copy link

fn wrap_value(value: Value) -> Value {

I'm trying to understand the purpose of this function. AFAICT this is replacing any empty map inside a Value::Object with a Map::new(). However, my impression is that these should be equivalent... am I missing something here?

 fn wrap_value(value: Value) -> Value { 
     match value { 
         // If the value is an object, check if it's empty 
         Value::Object(map) => { 
             if map.is_empty() { 
                 // Wrap empty map as an empty JSON object 
                 Value::Object(Map::new()) 
             } else { 
                 // Recursively wrap each key-value pair in the map 
                 Value::Object(map.into_iter().map(|(k, v)| (k, wrap_value(v))).collect()) 
             } 
         } 
         // If the value is an array, recursively wrap each element 
         Value::Array(arr) => Value::Array(arr.into_iter().map(wrap_value).collect()), 
         // If the value is null, return it as is 
         Value::Null => Value::Null, 
         // For primitive values, return them as is 
         other => other, 
     } 
 } 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant