Skip to content

json: Improve ergonomics by changing &String to &str in methods and adding Indexing #18544

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

Merged
merged 1 commit into from Nov 4, 2014
Merged

Conversation

ghost
Copy link

@ghost ghost commented Nov 2, 2014

Working with external Json is pretty unergonomic right now, and has a lot of unnecessary allocations, because everything needs to be converted to String.

find, find_path, and search now use &str rather than &String.

Indexing can be done with &str and uint, depending on whether the Json is an Object or a List.

[breaking-change]

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (or someone else) soon.

fn index<'a>(&'a self, index: &I) -> &'a Json {
index.index_json(self)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a number of recent changes to traits and such, you should actually be able to implement ops::Index<&'a str, Json> for Json as well as ops::Index<uint, Json> for Json without needing this trait, perhaps that could be tried first?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't realise that, thanks. That's great.

Json's find, find_path, and search methods now use &str rather
than &String.

Json can now be indexed with &str (for Objects) and uint
(for Lists).

Tests updated to reflect this change.

[breaking-change]
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Nov 4, 2014
@bors bors merged commit ab9a1b7 into rust-lang:master Nov 4, 2014
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

Successfully merging this pull request may close these issues.

5 participants