Feature request #2

Closed
opened 4 years ago by Ghost · 2 comments
Ghost commented 4 years ago

Adding an array merge special symbol (*).

proposal:


let mut test_inner_array = Value::Null;
test_inner_array.dot_set("name", Value::String(String::from("Google"))).unwrap();
assert_eq!(json!({"name" : "Google"}), test_inner_array);

test_inner_array.dot_set("todos.+", Value::String(String::from("Go to class"))).unwrap();
assert_eq!(json!({"name" : "Google", "todos" : ["Go to class"] }), test_inner_array);

test_inner_array.dot_set("todos.+", Value::String(String::from("Fish"))).unwrap();
assert_eq!(json!({"name" : "Google", "todos" : ["Go to class","Fish"] }), test_inner_array);

let array = vec![Value::String(String::from("Gold")),Value::String(String::from("Fish"))];
test_inner_array.dot_set("todos.*", Value::Array(array)).unwrap();
assert_eq!(json!({"name" : "Google", "todos" : ["Fish","Gold","Go to class"] }), test_inner_array);

Adding an array merge special symbol (*). proposal: ```rust let mut test_inner_array = Value::Null; test_inner_array.dot_set("name", Value::String(String::from("Google"))).unwrap(); assert_eq!(json!({"name" : "Google"}), test_inner_array); test_inner_array.dot_set("todos.+", Value::String(String::from("Go to class"))).unwrap(); assert_eq!(json!({"name" : "Google", "todos" : ["Go to class"] }), test_inner_array); test_inner_array.dot_set("todos.+", Value::String(String::from("Fish"))).unwrap(); assert_eq!(json!({"name" : "Google", "todos" : ["Go to class","Fish"] }), test_inner_array); let array = vec![Value::String(String::from("Gold")),Value::String(String::from("Fish"))]; test_inner_array.dot_set("todos.*", Value::Array(array)).unwrap(); assert_eq!(json!({"name" : "Google", "todos" : ["Fish","Gold","Go to class"] }), test_inner_array); ```
Owner

That's not possible without restricting dot_set to PartialEq types, I don't want to do that - and you would have to implement all the other set operations for completeness as well.

You can currently do this using the dot_get_mut() method

That's not possible without restricting `dot_set` to `PartialEq` types, I don't want to do that - and you would have to implement all the other set operations for completeness as well. You can currently do this using the `dot_get_mut()` method
Poster

ok i understand, i though it will more complete with the merge feature.

Thanks

ok i understand, i though it will more complete with the merge feature. Thanks
Ghost closed this issue 4 years ago
Sign in to join this conversation.
No Label
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: packages/json_dotpath#2
Loading…
There is no content yet.