diff options
Diffstat (limited to 'examples/simple.rs')
-rw-r--r-- | examples/simple.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/simple.rs b/examples/simple.rs new file mode 100644 index 0000000..a0a5860 --- /dev/null +++ b/examples/simple.rs @@ -0,0 +1,45 @@ +use std::fmt::Debug; + +use ridicule::mock; + +trait SomeFoobar +{ + fn do_something(&self) -> bool; +} + +trait Foo +{ + fn bar<Baz>(&self, num: u128) -> Baz; + + fn biz<Fiz: Debug, Bar>(&self, fiz: Fiz) -> &Bar; + + fn baz<Foobar>(&self, name: &str, foobar: Foobar) + where + Foobar: SomeFoobar; +} + +mock! { + MockFoo; + + impl Foo for MockFoo { + fn bar<Baz>(self: (&Self), num: u128) -> Baz; + + fn biz<Fiz: (Debug +), Bar>(self: (&Self), fiz: Fiz) -> &Bar; + + fn baz<Foobar>(self: (&Self), name: &str, foobar: Foobar) + where ( + Foobar: SomeFoobar + ); + } +} + +fn main() +{ + let mut mock_foo = MockFoo::new(); + + mock_foo.expect_bar().returning(|_me, num| { + println!("bar was called with {num}"); + }); + + mock_foo.bar::<()>(123); +} |