rust-fuzz / rust-fuzz/arbitrary

Support arbitrary 🥁 collections

Open
#155 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
880
Forks
93
PR merge metrics
No merged PRs in 30d

Description

I would like to be able to derive(Arbitrary) on a custom struct that happens to contain various collections that aren't in std (e.g. DashMap, SmallVec). I could add optional dependencies on dashmap and smallvec directly to the arbitrary crate, but I'd prefer to do this more generically so that it works for any collection.

I tried to do that as follows:

impl<'a, T: Arbitrary<'a>, C: FromIterator<T>> Arbitrary<'a> for C {
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self> {
        u.arbitrary_iter().collect()
    }
}

which didn't work:

 1  error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
     --> /Users/jyn/src/arbitrary/src/lib.rs:1158:10
      |
 1158 | impl<'a, T: Arbitrary<'a>, C: FromIterator<T>> Arbitrary<'a> for C {
      |          ^ unconstrained type parameter

I have two questions:

  1. Before I spent more time on it, is this a feature you're interested in?
  2. Do you have suggestions for how to get it working?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib.rs around the attempted Arbitrary implementation at line 1158 and review how arbitrary_iter is intended to be used. Investigate the unconstrained type-parameter error and the project's preferred API for supporting collections outside the standard library. Done should be defined as a feasible generic approach for custom collections such as DashMap and SmallVec.

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
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.