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

Allow mocking generic constructor methods #11

Closed
asomers opened this issue Aug 1, 2019 · 0 comments
Closed

Allow mocking generic constructor methods #11

asomers opened this issue Aug 1, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@asomers
Copy link
Owner

asomers commented Aug 1, 2019

Currently Mockall can't mock a constructor method for a generic struct that has bounds on its generic parameters. For example:

mock! {
    pub Foo<T: Default +'static> {
        fn build<T2: Default + 'static>() -> MockFoo<T2>;
    }
}

produces errors like

error[E0277]: the trait bound `T2: std::default::Default` is not satisfied
  --> mockall/tests/mock_generic_constructor_2.rs:7:1
   |
7  | / mock! {
8  | |     pub Foo<T: Default +'static> {
9  | |         fn build<T2: Default + 'static>() -> MockFoo<T2>;
10 | |     }
11 | | }
   | |_^ the trait `std::default::Default` is not implemented for `T2`
   |
   = help: consider adding a `where T2: std::default::Default` bound
@asomers asomers added the enhancement New feature or request label Aug 1, 2019
@asomers asomers closed this as completed in 6cdded6 Aug 2, 2019
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

No branches or pull requests

1 participant