Derive `Arbitrary` for types with lifetimes
mcy opened this issue · comments
derive(Arbitrary)
currently won't derive Arbitrary
if the type has a lifetime parameter in it. Most of the time this is fine, because Arbitrary: 'static
. However, it seems like it would be possible to implement Arbitrary
if all of the type parameters were set to 'static
. This is somewhat inconsistent with Cow<'static, impl Arbitrary>: Arbitrary
.
I haven't looked into how hard this would be, but I'm willing to mail a change adding this (maybe behind a Cargo feature?) if maintainers would consider it a useful addition.
Yeah, if the lifetime is 'static
then the derive should handle it.
The derive's code is in ./derive/src/lib.rs
. I'm not sure off the top of my head what would need to change in there to support this.
I think I didn't phrase what I meant correctly. I want the following behavior:
#[derive(Arbitrary)]
struct Foo<'a, 'b, ...> { ... }
// Generated impl:
impl Arbitrary for Foo<'static, 'static, ...> { ... }
I believe that this should be "easy", by blindly rewriting every lifetime into 'static
. I would have liked to write
#[derive(Arbitrary)]
type StaticFoo = Foo<'static, 'static, ...>;
I feel this is less surprising syntax but not something proc macros can do AFAIK, since they don't have type information available.
Done in #63