From 9ae69bc7024865324e21d3480954e010119ff6e2 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 20 Mar 2023 23:44:15 +0100 Subject: docs: add basic example --- examples/basic.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/basic.rs (limited to 'examples/basic.rs') diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..a157413 --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,28 @@ +use ridicule::mock; + +trait Foo: Sized +{ + fn bar(&self, num: u128) -> &Self; +} + +mock! { + MockFoo {} + + impl Foo for MockFoo + { + fn bar(&self, num: u128) -> &Self; + } +} + +fn main() +{ + let mut mock_foo = MockFoo::new(); + + mock_foo.expect_bar().returning(|me, num| { + println!("bar was called with {num}"); + + me + }); + + mock_foo.bar(123); +} -- cgit v1.2.3-18-g5258