I tried making this piece of code below work. It gets close to the real implementation, but it is slightly different.
pub async fn do_some_client_stuff<'a>(cfg: &'a Config) {
// setup mutable client
let mut client = Client::new(cfg.addr, ...);
// try to connect
if let Err(err) = client.connect().await {
// ^^^^^^^ signature: pub async fn connect(&mut self) -> Result<(), Error>
return Self::panic(Reason::new(format!("Could not client 1: {}", err).as_str()))
}
// do some other stuff with the client (reusage of the cient)
// ...
The problem I have comes down to this error:
required for the cast from `Pin<Box<[async block@###.rs:69:1: 73:3]>>` to `Pin<Box<(dyn Future<Output = ###> + Send + 'async_trait)>>```
I know one of the types inside the config does not have the copy trait and thus I cannot use the pass by value. So I want to pass a `&mut Client` that takes ownership and returns ownership eventually after it is completed so I can put the value in another struct. Am I missing something?