The new syntax follows a standard MetaListIdent format and renders more nicely in some editors than the custom "'a = co" syntax. The new syntax also makes it easier to declare multiple lifetime parameters with the same variance, at the cost of being slightly harder to declare mixed variances since they need separate attributes.
The processing of these attributes is pretty robust to various edge cases, as discussed in the updated docstring.
Generated Static/Transient impls
The generated impls have been slightly tweaked; the 'static type bounds are now pushed to the where clause instead of the generics list, and it is better at avoiding duplicate 'static bounds.
Before:
#[derive(Transient)]
struct S<'a, T1, T2, T3: 'static>(&'a T) where T2: 'static; // only T1 needs a new bound
unsafe impl<'a, T1: 'static, T2: 'static, T3: 'static + 'static> Transient for S<'a, T1, T2, T3>
where
T2: 'static
{
type Static = S<'static, T1, T2, T3>;
type Transience = Inv<'a>;
}
After:
#[derive(Transient)]
struct S<'a, T1, T2, T3: 'static>(&'a T) where T2: 'static; // only T1 needs a new bound
unsafe impl<'a, T1, T2, T3: 'static> Transient for S<'a, T1, T2, T3>
where
T1: 'static
T2: 'static
{
type Static = S<'static, T1, T2, T3>;
type Transience = Inv<'a>;
}
The macro now generates a module for the struct that contains a check function for each declared variance, instead of using a nested function. I also renamed to the test lifetime depending on the variance requested to make the error message slightly more helpful, but it still is not great.
This PR includes another significant rework of the derive macro, building on those from PR #3 and the v0.3.0 tag.
Excluding any implementation/cosmetic changes, the list of changes are summarized below (only the first of which impacts the public API):
Variance declaration attribute syntax (public API)
The "variance" helper attribute has been replaced by separate "covariant" and "contravariant" attributes, which are used a bit differently:
Before:
After:
The new syntax follows a standard MetaListIdent format and renders more nicely in some editors than the custom "'a = co" syntax. The new syntax also makes it easier to declare multiple lifetime parameters with the same variance, at the cost of being slightly harder to declare mixed variances since they need separate attributes.
The processing of these attributes is pretty robust to various edge cases, as discussed in the updated docstring.
Generated
Static
/Transient
implsThe generated impls have been slightly tweaked; the
'static
type bounds are now pushed to thewhere
clause instead of the generics list, and it is better at avoiding duplicate'static
bounds.Before:
After:
Generated variance validation (implementation detail)
The macro now generates a module for the struct that contains a check function for each declared variance, instead of using a nested function. I also renamed to the test lifetime depending on the variance requested to make the error message slightly more helpful, but it still is not great.
Before:
After: