Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding a lifetime parameter to Arbitrary #43

Closed
fitzgen opened this issue May 8, 2020 · 1 comment
Closed

Consider adding a lifetime parameter to Arbitrary #43

fitzgen opened this issue May 8, 2020 · 1 comment

Comments

@fitzgen
Copy link
Member

fitzgen commented May 8, 2020

If we tweaked the Arbitrary definition into this:

pub trait Arbitrary<'a>: Sized {
    fn arbitrary(u: &mut Unstructured<'a>) -> Result<Self>;

    // ...
}

Then we would allow implementing Arbitrary for things that borrow from the input string:

struct HasBorrow<'a> {
    borrow: &'a [u8],
}

impl<'a> Arbitrary<'a> for HasBorrow<'a> {
    fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result<HasBorrow<'a>> {
        let size = u.arbitrary_byte_size()?;
        let borrow = u.get_bytes(size)?;
        Ok(HasBorrow { borrow })
    }
}

There are two concerns, off the top of my head:

  1. This is a breaking change, and shouldn't be done lightly. Perhaps delayed until we have more breaking changes that we can roll up into one release.

  2. Right now, Arbitrary requires that types that implement it be 'static and I can't remember why. There sure are a bunch of errors when I remove this bound though. Anyways, this would also have to be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants