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

mock generic methods returning non-static values #86

Merged
merged 6 commits into from
Nov 30, 2019

Conversation

asomers
Copy link
Owner

@asomers asomers commented Nov 30, 2019

mock generic methods returning non-static values

It's now possible to mock generic methods whose return values' lifetimes are
chosen by the caller. This is especially useful for methods that return
std::future::Future.

There are presently two restrictions:

  1. static methods and bare functions of this type are not supported
  2. The expectations' return values must be 'static. That can often be
    worked-around via an unsafe lifetime transmute.

Hopefully both of those restrictions will be lifted in time.

Fixes #76

I'm not sure why I added it in the first place, but it doesn't seem to
be required now.
This is an internal refactor only; there is no functional change.
It's now possible to mock generic methods whose return values' lifetimes are
chosen by the caller.  This is especially useful for methods that return
std::future::Future.

There are presently two restrictions:
1) static methods and bare functions of this type are not supported
2) The expectations' return values must be 'static.  That can often be
   worked-around via an unsafe lifetime transmute.

Hopefully both of those restrictions will be lifted in time.

Fixes #76
@asomers asomers merged commit b2d762e into master Nov 30, 2019
@asomers asomers deleted the generic_return_nonstatic3 branch December 3, 2019 02:00
asomers added a commit that referenced this pull request Dec 6, 2019
The regression was probably introduced by PR #86
asomers added a commit that referenced this pull request Dec 6, 2019
The regression was probably introduced by PR #86
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow mocking generic methods with non-'static return values
1 participant