Skip to content

buffa-types --features arbitrary fails: Bytes doesn't implement Arbitrary #88

@iainmcgin

Description

@iainmcgin

Since #51 changed Any.value from Vec<u8> to bytes::Bytes, buffa-types no longer compiles with --features arbitrary:

$ cargo build -p buffa-types --features arbitrary
error[E0277]: the trait bound `buffa::bytes::Bytes: Arbitrary<'_>` is not satisfied

The bytes crate doesn't provide an Arbitrary impl, and the arbitrary crate doesn't provide one for Bytes either.

This also means cargo doc --workspace --all-features and cargo clippy --workspace --all-features fail at the compile step, which is how it surfaced.

Options

  1. #[arbitrary(with = ...)] on Any.value via codegen field_attribute for the WKT gen — generate a Vec<u8> then .into(). Keeps the derive, scopes the workaround to the one field.
  2. Runtime helper in buffa::__privatefn arbitrary_bytes<'a>(u: &mut Unstructured<'a>) -> arbitrary::Result<Bytes> that codegen attaches to every bytes_fields-typed field. Generalizes (1) to user bytes_fields too (which have the same problem).
  3. Drop #[derive(Arbitrary)] on Any and hand-write the impl in buffa-types/src/any_ext.rs.

(2) is probably right since any user with bytes_fields + generate_arbitrary(true) hits the same wall. Filing for 0.4.1 since it's a feature-flag compile break.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions