From 5eb823896f01146df0d4ed6c296ef7dd445ccbbf Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 1 Apr 2023 15:27:09 +0200 Subject: fix: make expectation returning method unsafe --- examples/generic_method.rs | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'examples/generic_method.rs') 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::() - .returning(|_me, num| { + unsafe { + mock_foo.expect_bar::().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::(123), "Hello".to_string()); assert_eq!(mock_foo.bar::(123), "Hello".to_string()); -- cgit v1.2.3-18-g5258