Skip to content

Implement Arbitrary for bitflags? #248

@sunfishcode

Description

@sunfishcode

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)
    }
}

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