dogamak / xcbars

Bar library created with rust and xcb.
Apache License 2.0
1 stars 1 forks source link

Macro `composite!` doesn't work. #1

Closed dogamak closed 7 years ago

dogamak commented 7 years ago

Macro tries to implement From<&str> and From<C> where C: ComponentCreator for the same type, which is local to the macro scope. However rust's orphan rules don't allow blanket impls with non-local generic types.

This means that the macro does work inside the xcbars crate, but fails to compile in other crates, such as the example in examples/bar.rs.

chrisduerr commented 7 years ago

I've never done anything with macros before but I'd love to look into this. Any hints to what I could try to make this work?

dogamak commented 7 years ago

The issue is not really with anything macro related, but instead with the orphan rules. This will probably need some juggling with trait definitions and generics until the compiler is happy.

There's this excellent article, Little Orphan Impls, which I should read too, that goes into details of orphan rules.

Basically, this is help wanted because I honestly have no idea how this should work. :sweat_smile: I asked @sector-f about this too but I haven't heard about him since then...

chrisduerr commented 7 years ago

I'll look into it. Maybe I can figure something out. Don't get your hopes up tho. :D

dogamak commented 7 years ago

I should probably mention that the macro worked inside the xcbars crate, but stopped working after I moved it from src/lib.rs to examples/bar.rs, which is it's own "crate".

chrisduerr commented 7 years ago

Why exactly is it necessary to define the SubComponent struct inside the macro? It seems to compile when moving it to component.rs.

dogamak commented 7 years ago

It does? Well, that's great! No, it doesn't really need to be defined inside the macro, it's just that it's an implementation detail of the macro and now we have to expose it to the user if it's moved outside the macro definition.

Any implementation detail is, however, rather pointless if the implementation doesn't work, so please create pull-request if it works properly and I'll merge it.

dogamak commented 7 years ago

Fixed with #16. There was a warning originating from within the macro, which can be really confusing. I fixed it in 65c33ef8c41ba3c246a79c5e764b5c3cce5cf2d5.