-
Notifications
You must be signed in to change notification settings - Fork 66
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
Can't mock trait containing function that takes an argument of type Option<&T>
#61
Comments
Yes, this is a problem. More generally, the only arguments that Mockall really supports are |
Hi, is there a workaround for this issue for generic traits? If not, how could this be fixed in mockall? |
The only workaround I know of is to change the trait's definition in test mode to take a |
I see, thanks! |
I'm a fool. I didn't realize that the workaround is trivial: declare an explicit generic lifetime. That's actually worked ever since 0.5.0 (PR #48). Do it like this: #[automock]
trait Test<T> {
fn test<'a>(value: Option<&'a T>);
} |
I think I'm going to close this issue rather than create an enhancement for it. The cost-benefit ratio doesn't seem very good, given how easy the workaround is. |
Seen using mockall 0.5.1 on both stable and nightly.
For example, trying to compile the following fails.
Workaround
If
T
is known it's possible to work around this by specifying a lifetime parameter in the method definition, e.g. the following worksIf the trait is generic this fails with a different error.
The text was updated successfully, but these errors were encountered: