rusty_paseto icon indicating copy to clipboard operation
rusty_paseto copied to clipboard

Purpose of internal function `wrap_value`

Open Imberflur opened this issue 1 year ago • 0 comments

https://github.com/rrrodzilla/rusty_paseto/blob/2e60fdd447d8e3816456f59992c47f23af5ada90/src/generic/builders/generic_builder.rs#L184

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, 
     } 
 } 

Imberflur avatar Aug 09 '24 22:08 Imberflur