ITADN
blueglyph/trait_gen

版本发布 8

v2.0.4
? · 2025-05-11

This release improves a few error messages.

v2.0.4
? · 2025-05-11

This release improves a few error messages.

Bye, syn v1v2.0.3
? · 2025-05-10

This release switched a dependency from `proc-macro-error` to `proc-macro-error2`, so that compiling `syn v1`—on top of `syn v2`!—isn't required any more. I wish I saw that earlier; it speeds up the compilation quite a bit. Note that, while `proc-macro-error` hasn't been updated for years, it looks like `proc-macro-error2` has been left on its own since the port to `syn v2` was done a few months ago by another author (my thanks to them). There are pending issues and pull requests that haven't been addressed since then, unfortunately, but for now, it's the better choice.

v2.0.2
? · 2025-05-10

This release doesn't change anything functionally; it's just refactoring of the code.

v2.0.1
? · 2025-05-07

This release fixes a few lint issues and corrects a few typos. Nothing fancy.

Permutationsv2.0.0
? · 2025-05-07

This release adds several permutation formats for typical use-cases: - `#[trait_gen(T, U -> u8, u16, u32)]` is a handy shortcut for ``` #[trait_gen(T -> u8, u16, u32)] #[trait_gen(U -> u8, u16, u32)] ``` - `#[trait_gen(T != U -> u8, u16, u32)]` does the same but only for T != U, so excluding (u8, u8), (u16, u16), and (u32, u32). ```rust struct Wrapper<T>(T); // The types T and U must be different to avoid the compilation error // "conflicting implementation in crate `core`: impl<T> From<T> for T" #[trait_gen(T != U -> u8, u16, u32)] impl From<Wrapper<U>> for Wrapper<T> { /// converts ${U} to ${T} fn from(value: Wrapper<U>) -> Self { Wrapper(T::try_from(value.0) .expect(&format!("overflow when converting {} to ${T}", value.0))) } } ``` - `#[trait_gen(T < U -> u8, u16, u32)]` generates the code for index(T) < index(U) in the given list, so (T, U) = (u8, u16), (u8, u32), (u16, u32). It's the _position_ in the list that counts; e.g. the types are not sorted (on what criterion would they be sorted anyway?) or checked in any way. ```rust // `From` is only defined for integers with fewer bits (and we exclude a conversion to // the same type for the same reason as above) #[trait_gen(T < U -> u8, u16, u32)] impl From<Wrapper<T>> for Wrapper<U> { /// converts Wrapper<${T}> to Wrapper<${U}> fn from(value: Wrapper<T>) -> Self { Wrapper(U::from(value.0)) } } ``` - `#[trait_gen(T <= U -> u8, u16, u32)]` generates the code for (T, U) = (u8, u8), (u8, u16), (u8, u32), (u16, u16), (u16, u32), (u32, u32) ```rust // We only want to add integers with fewer bits or of the same type: #[trait_gen(T <= U -> u8, u16, u32)] impl Add<Wrapper<T>> for Wrapper<U> { type Output = Wrapper<U>; fn add(self, rhs: Wrapper<T>) -> Self::Output { Wrapper::<U>(self.0 + <U>::from(rhs.0)) } } ``` Also, version 2.0.0 - removes the old `in` and legacy formats - the generic argument must now have the turbofish format if `<..>` is required. Use `#[trait_gen(T::<U> -> ...)` and not `#[trait_gen(T<U> -> ...)`.

Negation in conditional attributesv1.2.0
? · 2025-05-02

This release changes the following: - adds a negation in 'trait_gen_if' (the `!` must be in first position after the opening parenthesis): ```rust use trait_gen::{trait_gen, trait_gen_if} trait TypeEq<U> { fn same_type(&self, other: &U) -> bool; } #[trait_gen(T -> u8, u16, u32)] #[trait_gen(U -> u8, u16, u32)] impl TypeEq<U> for T { #[trait_gen_if(T in U)] fn same_type(&self, _other: &U) -> bool { true } #[trait_gen_if(!T in U)] fn same_type(&self, _other: &U) -> bool { false } } ``` Note: Attaching an attribute to an expression is still experimental, so we can't simplify the example above, unfortunately. - `trait_gen_if` and `type_gen_if` must now be declared. I didn't bump the version to 2.x, even if it's technically not back-compatible because of that; the change is minor and so is the current use of this macro. What can I say; I'm flawed.

v1.1.2
? · 2025-04-28

This release improves the error messages a little further. Now, when something's amiss in the outer attribute or in inner trait_gen/trait_gen_if attributes, the expected location is underlined in the error message and the appropriate help message is given.