diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-19 13:45:07 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-19 13:45:07 +0100 |
commit | 657673f4a25a2a7299d3751d54d9597635bc529d (patch) | |
tree | 0a1677d1b53958f19f392e5fc11f21d7f659485c /examples/generic_method.rs | |
parent | d03c747cfef277fda5823e08784c94c30c7f3964 (diff) |
docs: add examples
Diffstat (limited to 'examples/generic_method.rs')
-rw-r--r-- | examples/generic_method.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/generic_method.rs b/examples/generic_method.rs new file mode 100644 index 0000000..8dc4650 --- /dev/null +++ b/examples/generic_method.rs @@ -0,0 +1,36 @@ +use ridicule::mock; + +trait Foo +{ + fn bar<Baz>(&self, num: u128) -> Baz; +} + +mock! { + MockFoo {} + + impl Foo for MockFoo + { + fn bar<Baz>(&self, num: u128) -> Baz; + } +} + +fn main() +{ + let mut mock_foo = MockFoo::new(); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + + "Hello".to_string() + }); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + + 128u8 + }); + + assert_eq!(mock_foo.bar::<String>(123), "Hello".to_string()); + + assert_eq!(mock_foo.bar::<u8>(456), 128); +} |