Closed danimihalca closed 7 months ago
It's a lifetime problem. The argument of returning_st
does indeed need to be static, for complicated reasons. But that's ok, if you do it like this:
use std::sync::{Arc, Mutex};
let mut captured_callback_wrapper = Arc::new(Mutex::new(CallbackWrapper::default()));
let ccw2 = captured_callback_wrapper.clone();
mock_service.expect_exec().returning_st(move |_request, callback_wrapper| {
*ccw2.lock().unwrap() = callback_wrapper;
()
});
Understood. Thanks for the clarification and solution!
Hi. I'm a rather new user of your testing framework (and with Rust in general), and I was wondering if there is a way to capture the arguments passed to a mocked function (something similar to Google Mock's SaveArg action if you're familiar). After experimenting with mockall, my first intention was to do it in the returning methods from an Expectation, but I've encountered some lifetime issues.
Below is a small implementation example, a mocked trait which receives a wrapped callback as an argument, which I try to move to the main test scope.
The following errors are present where the closure is set for returning_st:
Am I using the API wrong, or for some reason, it expects that whatever is captured in returning_st's closure to have a static lifetime?