mockall_examples/lib.rs
1// vim: tw=80
2//! Examples of mock objects and their generated methods.
3//!
4//! This crate only exists to document the autogenerated methods of the
5//! [`Mockall`](https://docs.rs/mockall/latest/mockall)
6//! crate. You should never depend on this crate.
7#![deny(missing_docs)]
8#![deny(warnings)]
9
10#[cfg(doc)]
11use mockall::*;
12
13/// A basic trait with several kinds of method.
14///
15/// It is mocked by the [`MockFoo`](struct.MockFoo.html) struct.
16#[cfg(doc)]
17#[automock]
18pub trait Foo {
19 /// A method with a `'static` return type
20 fn foo(&self, x: i32, y: i16) -> i32;
21
22 /// A method returning a reference
23 fn bar(&self, x: i32) -> &i32;
24
25 /// A method returning a mutable reference
26 fn baz(&mut self, x: i32) -> &mut i32;
27
28 /// A method returning a `'static` reference
29 fn bean(&self) -> &'static i32;
30
31 /// A static method
32 fn bang(x: i32) -> i32;
33}
34
35/// A trait implemented by a Struct we want to mock
36pub trait Bah {
37 /// Some trait method
38 fn bah(&self);
39}
40
41#[cfg(doc)]
42mock! {
43 /// structs can be mocked with `mock!`
44 ///
45 /// Their mock methods have an identical API to the methods generated by
46 /// `#[automock]`
47 pub Boo {
48 /// A method on a struct
49 fn boo(&self);
50 }
51 /// An implementation of a trait on a mocked struct
52 trait Bah {
53 fn bah(&self);
54 }
55}
56
57#[cfg(doc)]
58#[automock(mod mock_ffi;)]
59extern "C" {
60 /// A foreign "C" function
61 pub fn ffi_func();
62}
63
64#[cfg(all(doc, feature = "nightly"))]
65/// Mock this entire module
66#[automock]
67mod a_module {
68 /// A function in a mocked module
69 pub fn modfunc() {
70 unimplemented!()
71 }
72}