Skip to content
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

Use Cow<str> in JSON parsers #545

Closed
CryZe opened this issue Jul 26, 2022 · 0 comments · Fixed by #546
Closed

Use Cow<str> in JSON parsers #545

CryZe opened this issue Jul 26, 2022 · 0 comments · Fixed by #546
Labels
enhancement An improvement for livesplit-core. parsing This is about one of the parsers. performance Affects the performance of the code. suitable for contributions The issue is suitable those who are contributing to livesplit-core.

Comments

@CryZe
Copy link
Collaborator

CryZe commented Jul 26, 2022

It was under the impression that you can't borrow with serde_json, but it's totally possible. The API directly supports it. The only thing you need to be careful about are escaped strings, but for those you can just use Cow to handle the owned unescaped case. Apparently there's an annotation you need to use though to specify that you prefer a borrowed str if possible on such a container. Each such field needs to be annotated with #[serde(borrow)]

@CryZe CryZe added enhancement An improvement for livesplit-core. parsing This is about one of the parsers. performance Affects the performance of the code. suitable for contributions The issue is suitable those who are contributing to livesplit-core. labels Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An improvement for livesplit-core. parsing This is about one of the parsers. performance Affects the performance of the code. suitable for contributions The issue is suitable those who are contributing to livesplit-core.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant