Simple scenario to run into such a problem.
You want a setup() method for your integration test. From checking several popular github project the idiom is to return a Struct e.g TestEnv from such a method owning the precondition instances. This is just not possible to do in one struct, if one of those preconditions has a reference.
Concrete example. Lets say you are implementing a rest client to a http api with reqwest crate. Lets call it CatsClient. reqwest is managing its own connection pool and you are supposed to init it once and pass a refernce to the Cats Client
struct CatsClient<'a> {
http: &'a reqwest::Client
}
reqwest::Client can be instantiated with default headers and perhaps soon also with a base_url.
For testing each of the CatsClient endpoints, you would like to have some default reqwest::Client and also a CatsClient instantiated with some default values for convenience.
fn setup<'a>() -> TestEnv<'a> {
let http = reqwest::Client.new();
let cats_client = CatsClient { http: &http };
TestEnv {
http: http,
cats_client: cats_client
}
}
There is actually no way to move out both http and the cats_cilent struct out of the function (not even with a tuple), or am i missing something?
Here is some playground