-
Notifications
You must be signed in to change notification settings - Fork 1
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
Associated types fail to compile #23
Comments
Hi, to me this use case looks a lot like Truly inverted dependencies - static dispatch. What makes the trait mockable in that case is that the facade trait has no associated type. The associated type is in the "helper trait" that is only in use with The unimock library does not support associated types, and I don't think it's necessary to support it because it's possible to design oneself around it. The Rust realworld entrait example project uses this pattern a lot, if you need examples. |
Hi, my use case is a mongodb driver abstraction - we are taking a chunk of the It makes sense that I have a workaround, so feel free to close this if you don't want to support this feature. |
So, to understand better: Say you have Those would be two proper non-mocked applications from the entrait point of view. This is of course a plausible design, and entrait should definitely support this. This indeed looks like a proper bug and I'll look into it unless you feel like making a PR. |
Need to keep in mind that this type of trait would not be automatically mockable like other traits. The mock implementation has to be written manually, but the macro could tell the user this explicitly. I also tried to imagine other ways you could maybe achieve the same thing. The
and
? edit:
(assuming you can use boxing and dynamic dispatch) |
Hah, my traits are very far from being object safe. Lots of In terms of mocking and associated types, mockall has you specify those in the automock invocation. Or you can use |
Another use case for associated types is something like transaction support. I see that a database abstraction is pretty hard to model using only function calls. See also this URLO thread. I'll try to get something like this to work in rust-realworld-entrait. |
Hey @audunhalland, another associated type issue here!
The associated type disappears from the generated trait:
It also needs to be bound in the
entrait::Impl
block as:The text was updated successfully, but these errors were encountered: