Implement Arbitrary for bitflags?
Would it be worth it to have an optional implementation of Arbitrary (in the arbitrary crate) for bitflags types, to make it easier to use them in fuzzing?
I'm imagining something along the lines of this, added to the macro expansion when cfg(feature = "arbitrary") or so:
impl arbitrary::Arbitrary for $BitFlags {
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
Self::from_bits(u.arbitrary()).ok_or_else(|| arbitrary::Error::IncorrectFormat)
}
}
Can we think of any other implementation for Arbitrary that a consumer might want to add themselves? If not then this seems like a reasonable addition to me, since as I understand it, Arbitrary is meant to be a general API that different fuzzer implementations can lean on. Anything that makes fuzzing easier to get started with is worth doing! 😁
I've now submitted #260 implementing this.
We've recently published 2.0.0 that reworks the library internals to support new external trait implementations without breaking consumers. We should now be able to add an implementation for arbitrary following the support for serde as an example.