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

Improve Ownership Ergonomics of PromqlResult and Related Types #9

Merged
merged 3 commits into from
Dec 9, 2023
Merged

Improve Ownership Ergonomics of PromqlResult and Related Types #9

merged 3 commits into from
Dec 9, 2023

Conversation

VoltaireNoir
Copy link

@VoltaireNoir VoltaireNoir commented Dec 1, 2023

Summary

The existing library API only provides immutable references to the internal data of the Promql query result. This may be good for encapsulation but it becomes very limiting when ownership of the data is required. In the current implementation, owning the data requires cloning it, which can be very expensive if the data is large.

This PR attempts to mitigate that by allowing the user of the library to own the internal types by explicitly calling the relevant into_* methods.

Changes

  • The custom as_variant and is_variant methods on the Data type have been removed. Instead, the EnumAsInner derive macro is used to generate the same methods automatically. Additionally this also adds the into_variant methods which allow user to own the internal types.
  • PromqlResult, InstantVector, and RangeVector implement into_inner method
  • Sample now implements Copy

Maaz Ahmed added 3 commits December 1, 2023 15:50
The EnumAsInner derive macro automatically generates methods like as_*()/as_*_mut() or into_*(), providing mutable and owned types whenever required.
This avoids cloning the data when ownership is required, as the previous API only allowed immutable references to the internal data.
Since the inner types implement Copy, this improves the ergonomics by making Sample also Copy.
@puetzp
Copy link
Owner

puetzp commented Dec 5, 2023

Thank you for the PR. I will merge it and probably cut a new release by the end of the week. Right now I am a little busy with the day job.

@VoltaireNoir
Copy link
Author

Thank you for the PR. I will merge it and probably cut a new release by the end of the week. Right now I am a little busy with the day job.

Great! Let me know if I need to make any further changes to the PR.

@puetzp puetzp merged commit d4db8b8 into puetzp:master Dec 9, 2023
@puetzp
Copy link
Owner

puetzp commented Dec 9, 2023

I merged your PR and released a new version that contains your changes.
Thanks again!

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.

2 participants