Serde Deserialize lifetime interfering with local variable lifetime
You can use HRTB as @Jmb suggested in the comments:
impl WorkflowProcess {
async fn process<T>(&mut self, callback: impl Fn(T))
where
for<'a> T: Deserialize<'a>,
{
let r = self.rx.recv().await;
if let Some(v) = r {
let deserialized: T = {
let s: &str = v.as_str();
serde_json::from_str(s).unwrap()
};
callback(deserialized);
}
}
}
Playground