CycloneDX / CycloneDX/cyclonedx-rust-cargo
Refactor `.new_unchecked()` on enums into `impl From<&str>`
- Dominant language
- Rust
- Stars
- 178
- Forks
- 66
- PR merge metrics
- No merged PRs in 30d
Description
We have functions with signature `pub(crate) fn new_unchecked>(value: A) -> Self` on a number of enums, where the function converts any string to an enum variant and unrecognized strings go to the `Unknown(String)` variant.
It seems it would be more convenient and idiomatic to just `impl From<&str>` or `impl FromStr` instead of using a custom function. The generic `A: AsRef` will be separately monomorphised for every type it is used with, increasing compilation time and binary size.
A potentially significant change is that trait implementations are automatically public, so there is no way to make them `pub(crate)`. But exposing it publicly actually sounds like a good idea to me.
I originally brought this up in the review of #681
Contributor guide
Research direction
Search the repository for the pub(crate) new_unchecked entry points on enums and review the discussion in issue #681. Identify every affected enum and how its string conversion is used before choosing the trait approach. Done means the affected conversions use the requested public trait implementation, the old custom functions are no longer needed, and the project still builds and passes its existing checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100