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
Allow mocking non-'static structs #4
Comments
|
I think I've just run into this: Yields: I'm not using nightly. I'm using the Diesel ORM, so require the lifetimes to cope with string insertion on a struct like this: I've got a Can you suggest a workaround in this situation? |
|
Actually, you're running into a different problem. This issue concerns Situations like this can usually be dealt with eliminating the lifetimes when compiling in test mode. You can try something like this: #[automock]
trait RepositoryTrait {
#[cfg(not(test))]
fn create_foo<'insert>(&self, foo: &'insert NewFoo<'insert>);
#[cfg(test)]
fn create_foo(&self, foo: &'static NewFoo<'static>);
}Of course, that obviously imposes a new restriction on how you write your tests. Another possible workaround would be to redefine |
|
Thanks @asomers, that's done the trick for me! |
Constructor methods are not yet supported. Fixes #4 The gory details: * Generics of mock structs should not include lifetimes * deselfify before split lifetimes * Include rlifetimes in some impl blocks * Include some missing <> in an intermediate Generics object * Fix deselfify with lifetimes * Handle apparently unused lifetimes in split_lifetimes * Fix determination of whether a method is generic in method_types. There was some leftover logic from back when all methods of generic structs were treated as generic methods. * Remove lifetimes from Context objects
Constructor methods are not yet supported. Fixes #4 The gory details: * Generics of mock structs should not include lifetimes * deselfify before split lifetimes * Include rlifetimes in some impl blocks * Include some missing <> in an intermediate Generics object * Fix deselfify with lifetimes * Handle apparently unused lifetimes in split_lifetimes * Fix determination of whether a method is generic in method_types. There was some leftover logic from back when all methods of generic structs were treated as generic methods. * Remove lifetimes from Context objects
Mockall currently can't mock a struct or trait with a lifetime parameter. So something like this doesn't work:
The text was updated successfully, but these errors were encountered: