Replies: 1 comment 1 reply
-
|
Yes, there is an easy workaround. Use #[cfg(test)]
mockall::mock! {
pub StructWithLifetime<'a> {}
impl TraitWithAssociatedType for StructWithLifetime<'static> {
type Type = String;
fn method(&self, input: Self::Type) -> String;
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello. Currently I'm having to mock something like this:
But I keep getting an error related to the lifetime:
Strangely enough, when I inline the macro, the error appears to be here:
Specifically, the struct
Expectationhas no lifetime parameter, but theexpect_methodfunction returnsExpectation<'_>.I tried using automock on the implementation of the trait on the struct but got a similar error. And I do not think mocking the trait works for my case, because my understanding is that for that to work I have to define concrete types for the associated types, and in my tests I need to have a different mock for each associated type I have.
Is there a way around this? The struct needs the lifetime parameter because it contains a struct that needs it, so I cannot avoid having it.
Beta Was this translation helpful? Give feedback.
All reactions