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

Refine API #51

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Refine API #51

wants to merge 2 commits into from

Conversation

aleasims
Copy link
Contributor

@aleasims aleasims commented Feb 24, 2025

Changes

  • ByteUnit/CoreUnit/TimeUnit now use u64 instead of i64. It makes no sense to store them as signed, especially because parsing negative units always results in error.
  • Serialization helpers are now exposed in public API. This is needed because these types are public fields in different models, which are in public API.
  • Re-enabled linting and testing in CI. A bunch of tests were fixed. Old e2e tests were ignored. Clippy warnings fixed.
    UPD. moved to separate PR

Notes

Doing all this revealed a number of questions. They are not resolved in this PR, however I will list them here for further discussions.

  • Exposing units as public enums makes all of their variants public, which allows to create invalid {Byte,Core,Time}Unit::String variants. Probably private implementation pattern should be used here for better API:
    // public type
    pub struct ByteUnit {
        // private inner field
        inner: ByteUnitImpl,
    }
    // private implementation
    enum ByteUnitImpl { ... }
  • Multiplying unit value by factor may overflow and result in a panic. Although it's very unlikely to happened on real input, still probably should be handled.
  • There is an inconsistency between bytesize::ByteSize and gevulot_rs::models::ByteUnit. We use "megabyte" to represent mebibytes, but bytesize separates them. Because of that ByteUnit<DefaultFactorOneMegabyte>::from(1) and "1MB".parse::<ByteUnit>() are not the same.
  • CoreUnit doesn't implement fractional parse, however it was mentioned in tests. This doesn't work: "1.5cpus".parse::<CoreUnit>(). Do we want this?

@aleasims aleasims self-assigned this Feb 24, 2025
@aleasims aleasims requested review from trusch and tuommaki February 24, 2025 22:34
@aleasims aleasims marked this pull request as ready for review February 24, 2025 22:34
miax-gevu
miax-gevu previously approved these changes Feb 27, 2025
@aleasims
Copy link
Contributor Author

@miax-gevu thanks for the review
@trusch I'd really like you to take a look at this before merging (cause there are some open questions) when you have a bit of free time

@aleasims
Copy link
Contributor Author

aleasims commented Mar 4, 2025

To simplify review I moved all unrelated changes to separate PR:

This PR now contains only serialization helpers changes. (force-pushing to keep it clean)
The questions in PR description are still actual.

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