Hello,
I have the following borrow problem when trying to truncate a json::Array to 2 in length using cargo:json
I have a "fix" but I wondered what would be the ideal solution here. I have commented the borrow problems. There may also be another way to truncate the array, however I'd like to get the chosen method working first.
let first_two = op["operationStatuses"].members().take(2).cloned(); // Immutable borrow on "op"
let new_statuses = first_two.collect::<Vec<json::JsonValue>>();
op["operationStatuses"] = new_statuses.into(); // Mutable borrow on "op"
"Fix":
let os = op["operationStatuses"].clone(); // Clone must be separate let statement
let first_two = os.members().take(2).cloned();
let new_statuses = first_two.collect::<Vecjson::JsonValue>();
op["operationStatuses"] = new_statuses.into();
Other methods I've thought of could include Slicing a clone instead, or a filter predicate, which I will investigate shortly.