Skip to content

Using Strings as index #28

@nshtg

Description

@nshtg

Right now it's kind of verbose to do this:

let j_test = object!{
    "hi" => 123,
    "na" => 345
};
let mut j_test2 = json::JsonValue::new_object();
for (key, val) in j_test.entries() {
    j_test2["subsub"][key] = val.as_u32().into();
}

Error:

trait bound `json::JsonValue: std::ops::Index<&std::string::String>` is not satisfied

You have to write

j_test2["subsub"][&**key] = val.as_u32().into();

And if you use ref you have to write:

for (ref key, ref val) in j_test.entries() {
    j_test2["subsub"][&***key] = val.as_u32().into();
}

As an idea for improvements.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions