Skip to content

Support arbitrary 🥁 collections #155

@jyn514

Description

@jyn514

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions