diff options
author | HampusM <hampus@hampusmat.com> | 2023-04-01 15:27:09 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-04-01 15:27:09 +0200 |
commit | 5eb823896f01146df0d4ed6c296ef7dd445ccbbf (patch) | |
tree | 482ba87a3977f646dcff956affd47dac50a2d647 /examples/generic_method.rs | |
parent | ba865b581fbc1d0589b402b028f2bce70332891b (diff) |
fix: make expectation returning method unsafe
Diffstat (limited to 'examples/generic_method.rs')
-rw-r--r-- | examples/generic_method.rs | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/examples/generic_method.rs b/examples/generic_method.rs index c4e3214..c86864d 100644 --- a/examples/generic_method.rs +++ b/examples/generic_method.rs @@ -39,31 +39,35 @@ fn main() { let mut mock_foo = MockFoo::new(); - mock_foo - .expect_bar::<u16>() - .returning(|_me, num| { + unsafe { + mock_foo.expect_bar::<u16>().returning(|_me, num| { println!("bar was called with {num}"); "Hello".to_string() }) - .times(3); - - mock_foo.expect_bar::<&str>().returning(|_me, num| { - println!("bar was called with {num}"); - - 128u8 - }); - - mock_foo - .expect_abc::<&str, f64>() - .with( - function(|thing_a: &&str| thing_a.starts_with("Good morning")), - is_close(7.13081), - ) - .returning(|_me, _thing_a, _thing_b| { - println!("abc was called"); - }) - .times(1); + } + .times(3); + + unsafe { + mock_foo.expect_bar::<&str>().returning(|_me, num| { + println!("bar was called with {num}"); + + 128u8 + }); + } + + unsafe { + mock_foo + .expect_abc::<&str, f64>() + .with( + function(|thing_a: &&str| thing_a.starts_with("Good morning")), + is_close(7.13081), + ) + .returning(|_me, _thing_a, _thing_b| { + println!("abc was called"); + }) + } + .times(1); assert_eq!(mock_foo.bar::<u16>(123), "Hello".to_string()); assert_eq!(mock_foo.bar::<u16>(123), "Hello".to_string()); |