rust-fuzz / rust-fuzz/arbitrary
Consider a custom type for easier size hints
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 880
- Forks
- 93
- PR merge metrics
- No merged PRs in 30d
Description
When writing required manual Arbitrary implementations, one of the more painful elements is writing the size_hint() code, because it's a lot of arbitrary::size_hint::* function calls that must mirror the arbitrary() code. If size_hint() used a custom struct type instead of a tuple, this code could be made much more concise and legible using operators and method calls. For example, this size_hint method for one required and one possibly-required field,
fn size_hint(depth: usize) -> (usize, Option<usize>) {
arbitrary::size_hint::and(
Foo::size_hint(depth),
arbitrary::size_hint::or((0, Some(0)), Bar::size_hint(depth)),
)
}
could become something like
fn size_hint(depth: usize) -> arbitrary::SizeHint {
Foo::size_hint(depth) + (arbitrary::SizeHint::ZERO | Bar::size_hint(depth))
}
(The original code could become shorter with some uses, but the use is itself additional boilerplate to write, particularly since it needs to be placed inside a #[cfg(feature = "arbitrary")] if there is one.)
As written, this is, of course, a breaking change of type, so it would require an arbitrary 2.0, and this isn’t worth that. I only wish to present this idea for consideration in case breaking changes are needed for other reasons.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or entry point is named. Review the existing arbitrary::size_hint API and the proposed arbitrary::SizeHint operations, then assess whether a compatible migration path exists for a future breaking release. Done would require a concrete design decision rather than only considering the proposal.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 20/100