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 functions with unknown size type bounds #421

Merged
merged 4 commits into from
Oct 23, 2022

Conversation

HampusMat
Copy link
Contributor

A quick change to allow for mocked functions to have type bounds with unknown sizes.

For example:

use mockall::mock;

trait Foo {}

trait Bar {
    fn do_something<T>(&self) -> u32
    where
        T: 'static + ?Sized;
}

mock! {
    Foobar {}

    impl Bar for Foobar {
        fn do_something<T>(&self) -> u32
        where
            T: 'static + ?Sized;
    }
}

let mut foobar_mock = MockFoobar::new();

foobar_mock
    .expect_do_something::<dyn Foo>()
    .returning(|| 120);

let num = foobar_mock.do_something::<dyn Foo>();

println!("{num}");

Copy link
Owner

@asomers asomers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nice little fix. Don't forget to add it to the "Fixed" section of the CHANGELOG!

@asomers asomers merged commit b51cb30 into asomers:master Oct 23, 2022
asomers pushed a commit that referenced this pull request Mar 26, 2023
Allow mocking functions with unknown size type bounds
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.

None yet

2 participants