diff options
| author | HampusM <hampus@hampusmat.com> | 2023-03-20 23:44:15 +0100 | 
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2023-03-20 23:44:15 +0100 | 
| commit | 9ae69bc7024865324e21d3480954e010119ff6e2 (patch) | |
| tree | e19f6e385d642aac6df358a6cacaad7d8d625feb /examples | |
| parent | 7d19a8eae3fc911c0cee372b9a492ec203f4f45c (diff) | |
docs: add basic example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/basic.rs | 28 | 
1 files changed, 28 insertions, 0 deletions
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); +}  | 
