5

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Eyal leshem
  • 995
  • 2
  • 10
  • 21
  • 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 Answers1

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