From 657673f4a25a2a7299d3751d54d9597635bc529d Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 Mar 2023 13:45:07 +0100 Subject: docs: add examples --- examples/generic_trait.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 examples/generic_trait.rs (limited to 'examples/generic_trait.rs') diff --git a/examples/generic_trait.rs b/examples/generic_trait.rs new file mode 100644 index 0000000..d863d85 --- /dev/null +++ b/examples/generic_trait.rs @@ -0,0 +1,34 @@ +use std::fmt::Display; + +use ridicule::mock; + +trait Foo +{ + fn bar(&self, something: &Something); +} + +mock! { + MockFoo {} + + impl Foo 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); +} -- cgit v1.2.3-18-g5258