-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[Merged by Bors] - re-enable #[derive(TypeUuid)]
for generics
#4118
[Merged by Bors] - re-enable #[derive(TypeUuid)]
for generics
#4118
Conversation
Xoring would give |
Good point. Maybe we need A XOR B XOR C XOR UNIQUE1 should be distinct from |
Hm, so #[uuid = "11b483e0-594f-42b2-b004-8aea624cb2c1"]
struct TestDeriveStruct<#[uuid = "dadbf4fb-55b4-4e96-a3b2-b178bad890af"] T>(T); works, you can parse the attribute correctly with syn, however you still get the error message
I assume this is because derives are purely additive, so you can't remove the Alternatively you could have #[uuid = "11b483e0-594f-42b2-b004-8aea624cb2c1"]
#[uuid(T = "dadbf4fb-55b4-4e96-a3b2-b178bad890af")]
struct TestDeriveStruct<T>(T); |
XBagon@8fc04b0 |
a607b66
to
ddb2522
Compare
ddb2522
to
8ede521
Compare
I merged the version done by @XBagon, where the UUID is generated by a bitwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I also have a commit in this and had to work with the code, I'm approving of these changes 😄!
bors r+ |
Support for deriving `TypeUuid` for types with generics was initially added in #2044 but later reverted #2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
#[derive(TypeUuid)]
for generics#[derive(TypeUuid)]
for generics
Support for deriving `TypeUuid` for types with generics was initially added in bevyengine#2044 but later reverted bevyengine#2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
Support for deriving `TypeUuid` for types with generics was initially added in bevyengine#2044 but later reverted bevyengine#2204 because it lead to `MyStruct<A>` and `MyStruct<B>` having the same type uuid. This PR fixes this by generating code like ```rust #[derive(TypeUuid)] #[uuid = "69b09733-a21a-4dab-a444-d472986bd672"] struct Type<T>(T); impl<T: TypeUuid> TypeUuid for Type<T> { const TYPE_UUID: TypeUuid = generate_compound_uuid(Uuid::from_bytes([/* 69b0 uuid */]), T::TYPE_UUID); } ``` where `generate_compound_uuid` will XOR the non-metadata bits of the two UUIDs. Co-authored-by: XBagon <[email protected]> Co-authored-by: Jakob Hellermann <[email protected]>
Support for deriving
TypeUuid
for types with generics was initially added in #2044 but later reverted #2204 because it lead toMyStruct<A>
andMyStruct<B>
having the same type uuid.This PR fixes this by generating code like
where
generate_compound_uuid
will XOR the non-metadata bits of the two UUIDs.