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

Remove num_enum dependency #931

Merged
merged 3 commits into from
Feb 15, 2024
Merged

Remove num_enum dependency #931

merged 3 commits into from
Feb 15, 2024

Conversation

muzarski
Copy link
Contributor

Ref: #771
I believe this PR closes #857.

Motivation

To stabilize our API, we need to get rid of pre-1.0 crates. One of them is num_enum.

This crate allows us to automatically generate conversions from primitive types to enum values - however, its usages needs to be removed from the library.

Changes

To get rid of the dependency, we needed to implement converters ourselves.

This is why, we introduce a TryFromPrimitiveError struct which holds the information about the enum name and the actual value that we tried to parse.

Apart from that, we implement TryFrom for the types that used the num_enum crate:

  • impl TryFrom<u16> for Consistency
  • impl TryFrom<i16> for SerialConsistency
  • impl TryFrom<u8> for RequestOpcode
  • impl TryFrom<u8> for ResponseOpcode

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

Copy link
Collaborator

@piodul piodul left a comment

Choose a reason for hiding this comment

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

Two tiny nitpicks, otherwise LGTM.

scylla-cql/src/frame/mod.rs Outdated Show resolved Hide resolved
scylla-cql/src/frame/response/mod.rs Outdated Show resolved Hide resolved
Added a type which holds information about the error when parsing
an enum value from a primitive.
Replaced usages of num_enum, and implemented the corresponding
`TryFrom` traits for the types that used num_enum previously.
@muzarski
Copy link
Contributor Author

v2: addressed review comments

@muzarski muzarski requested review from Lorak-mmk and piodul February 15, 2024 11:04
@piodul
Copy link
Collaborator

piodul commented Feb 15, 2024

Cassandra tests failed on a known flaky test: #813. Rerunning CI.

@piodul piodul merged commit 29f6744 into scylladb:main Feb 15, 2024
11 checks passed
@Lorak-mmk Lorak-mmk mentioned this pull request May 9, 2024
@muzarski muzarski deleted the remove_num_enum branch October 29, 2024 14:35
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