Closed Ben-PH closed 1 year ago
This is not how Rust works. You cannot create a "Foo" that can be used in the same way as a "MockFoo". Rust is a strongly typed, statically typed language. A variable is either a Foo or a MockFoo, not both. The solution to your problem is to use #[mockall_double]
correctly. Or, if for some reason you can't, then you must straighten out all of your cfg
directives to ensure that you never pass a MockFoo
to a function expecting a Foo
or vice versa.
Closing. We discussed the issue in the linked discussion.
Related issue: #331
Related discussion: #478
When testing a function with a mocked implementation passed in, it must be a trait by virtue of the fact that a mocked struct is seen as a different type. This is problematic in the context where you do not wish to make the function generic on that input.
I'm not 100% sure what a good solution will look like, but here is a a rough first draft: