summaryrefslogtreecommitdiff
path: root/examples/generic_trait.rs
blob: d863d856061332910342653cba3e15ee21f8a2a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fmt::Display;

use ridicule::mock;

trait Foo<Something: Display>
{
    fn bar(&self, something: &Something);
}

mock! {
    MockFoo {}

    impl<Something: Display> Foo<Something> for MockFoo
    {
        fn bar(&self, something: &Something);
    }
}

fn main()
{
    let mut mock_foo = MockFoo::new();

    mock_foo.expect_bar().returning(|_me, something: &f32| {
        println!("bar was called with {something}");
    });

    mock_foo.expect_bar().returning(|_me, something: &f64| {
        println!("bar was called with {something}");
    });

    mock_foo.bar(&0.826f32);

    mock_foo.bar(&0.410f64);
}