I want to mock a regular single method in the module scope (not a trait or struct method), that will return a constant value, but I can't find any example in the docs.
Asked
Active
Viewed 1,525 times
5
-
that the closet thing to mock that i found until now : https://klau.si/blog/mocking-in-rust-with-conditional-compilation/ – Eyal leshem Jan 04 '20 at 18:20
1 Answers
6
The short answer is no, but the workarounds are pretty easy: 1) Turn your single free function into a static method of a struct, and mock the struct. 2) Put your single free function into a module, and mock the module (requires nightly).

Alan Somers
- 86
- 1
- 5