Skip to content
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

Support generic input parameters that are not 'static #52

Open
audunhalland opened this issue Mar 31, 2024 · 1 comment · May be fixed by #61
Open

Support generic input parameters that are not 'static #52

audunhalland opened this issue Mar 31, 2024 · 1 comment · May be fixed by #61
Labels
enhancement New feature or request

Comments

@audunhalland
Copy link
Owner

audunhalland commented Mar 31, 2024

(from https://stackoverflow.com/questions/76818001/use-mockall-crate-for-a-trait-with-trait-bounds)

trait MyTrait {
    fn process<T: Read>(&self, data: T) -> i32;
}

This currently yields a compile error due to missing T: 'static. But it's still possible to mock it, in a more limited sense. If the T is replaced with unimock::Impossible it's doable. What will be missing then is argument matching and access to the parameter in AnswerFn.

Consider using a different Impossible-like variant like MissingStaticBound, to serve as a diagnostic hint.

A problem is that it's impossible to statically detect whether a trait already has an implicit 'static bound. I think a solution to that could be something like:

#[unimock(api=MyTraitMock, skip_generic=Read)]
trait MyTrait {
    fn process<T: Read>(&self, data: T) -> i32;
}

if that's not too big of a hammer. I'd like to avoid sub-attributes for unimock, since those are difficult to combine with cfg_attr.

@audunhalland audunhalland added the enhancement New feature or request label Mar 31, 2024
@audunhalland
Copy link
Owner Author

audunhalland commented Jun 29, 2024

Of course, the macro should just require a syntactic + 'static even if implicit from the trait definition. With a MissingStaticBound error type, it should be clear why that parameter is left out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant