-
Notifications
You must be signed in to change notification settings - Fork 546
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
Derive convenience traits for PSO components and a few other types #1249
Conversation
There is a lot of structs with PhantomData that you added derives to. This is not perfect. Instead, we can have a macro for the simple case of something+phantom structs, macro generating the implementations of Eq, Hash, etc.
… On May 2, 2017, at 08:27, msiglreith ***@***.***> wrote:
@msiglreith approved this pull request.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@kvark Good idea! I can add such a macro, if you want, but in what crate/module would you like me to store it? Using a macro certainly sounds appealing in the long-term, but the effort of wiring it up and exporting it between crates might outweigh the advantages. I don't mind fixing each of the EDIT: Looking at the source of the |
It's just a few lines of code, and the only crate that would need to use it from the core is
Yep. |
Heh, interesting timing! Just as you commented this message, I pushed my manual fixes to my branch. Fair enough, I'll revise it once more and add the macro then. Would |
I think the macros is small enough so that it can live in |
I don't understand, what is the problem of deriving for a struct with |
@torkleyy it's not perfect in a way that these structs look very similar, and we end up with tons of code duplication. Nothing is wrong about |
As followup to @torkleyy 's question: The Eq implementation of PhantomData returns always true and the hashing is a no-op. |
@msiglreith I'm pretty sure that the original commenter was mistaken about @kvark Just curious, but if the structs in question contained a |
It would be safest to look at the code that |
We aren't cheating here. The limitation of |
@kvark Indeed (https://is.gd/7fse6V), but why is that? It could just do a |
@torkleyy surely it could be better... the answer lies somewhere within the |
Yeah, it does: use std::marker::PhantomData;
struct Foo;
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
struct Bar<T> {
value: u32,
phantom: PhantomData<T>,
}
impl Hash for Bar<Foo> { // Conflicting impls if #derive did the right thing
...
} |
Relevant issue: rust-lang/rust#26925 |
Happy to see this coming to a success! |
📌 Commit b31869a has been approved by |
Derive convenience traits for PSO components and a few other types ### Changed * Derived `Clone`, `Copy`, `Debug`, `Eq`, `Hash`, and/or `PartialEq` for a bunch of structs, mostly within the `gfx::pso::*` module. * Updated the `gfx_pipeline!` macro to automatically derive `Clone`, `Debug`, and `PartialEq` for the resulting `Data`, `Meta`, and `Init` structs. * Updated the `gfx_impl_struct_meta!` macro to automatically derive `Clone`, `Copy`, `Debug`, and `PartialEq` for the resulting struct. * Minor reformatting. ### Fixed * Eliminated TODOs for manually implementing `Eq`, `Hash`, and `PartialEq` on several structs which contain `PhantomData<T>` as data members. CC @kvark @msiglreith
☀️ Test successful - status |
Changed
Clone
,Copy
,Debug
,Eq
,Hash
, and/orPartialEq
for a bunch of structs, mostly within thegfx::pso::*
module.gfx_pipeline!
macro to automatically deriveClone
,Debug
, andPartialEq
for the resultingData
,Meta
, andInit
structs.gfx_impl_struct_meta!
macro to automatically deriveClone
,Copy
,Debug
, andPartialEq
for the resulting struct.Fixed
Eq
,Hash
, andPartialEq
on several structs which containPhantomData<T>
as data members.CC @kvark @msiglreith