1 // vim: tw=80 2 //! Examples of Mockall's generated code 3 use mockall::{mock, automock}; 4 5 /// Mock of a basic trait with several kinds of method. 6 /// 7 /// It is mocked by the [`MockFoo`](struct.MockFoo.html) struct. 8 #[automock] 9 pub trait Foo { 10 /// A method with a `'static` return type foo(&self, x: i32, y: i16) -> i3211 fn foo(&self, x: i32, y: i16) -> i32; 12 13 /// A method returning a reference bar(&self, x: i32) -> &i3214 fn bar(&self, x: i32) -> &i32; 15 16 /// A method returning a mutable reference baz(&mut self, x: i32) -> &mut i3217 fn baz(&mut self, x: i32) -> &mut i32; 18 19 /// A method returning a `'static` reference bean(&self) -> &'static i3220 fn bean(&self) -> &'static i32; 21 22 /// A static method bang(x: i32) -> i3223 fn bang(x: i32) -> i32; 24 } 25 26 /// A trait implemented by a Struct we want to mock 27 pub trait Bah { 28 /// Some trait method bah(&self)29 fn bah(&self); 30 } 31 32 mock! { 33 /// Mock of a struct 34 /// 35 /// Structs can be mocked with [`mock!`]. 36 /// Their mock methods have an identical API to the methods generated by 37 /// [`#[automock]`](automock). 38 pub Boo { 39 /// A method on a struct 40 fn boo(&self); 41 } 42 /// An implementation of a trait on a mocked struct 43 impl Bah for Boo { 44 fn bah(&self); 45 } 46 } 47 48 /// A module full of foreign C functions. 49 #[automock] 50 pub mod ffi { 51 extern "C" { 52 /// A foreign "C" function. ffi_func()53 pub fn ffi_func(); 54 } 55 } 56 57 /// Mock this entire module 58 #[automock] 59 pub mod my_module { 60 /// A function in a mocked module modfunc()61 pub fn modfunc() { 62 unimplemented!() 63 } 64 } 65