I have been using the following code to send a message and get a response back:
fn send_msg<'a,T,R>(msg :&T) -> R where T: Serialize, for<'d: 'static> R: Deserialize<'d> {
tx(&serde_json::to_string(msg).unwrap());
serde_json::from_str(&rx()).unwrap()
}
Playpen example: Rust Playground
Works fine on stable but compiles with a warning:
warning: unnecessary lifetime parameter `'d`
--> src/main.rs:20:59
|
20 | fn send_msg<'a,T,R>(msg :&T) -> R where T: Serialize, for<'d: 'static> R: Deserialize<'d> {
| ^^^^^^^^^^^
|
= help: you can use the `'static` lifetime directly, in place of `'d`
Clear warning only the suggested fix results in a compile error from the borrow checker. So far no problem I kind a excepted the warning for now but recently the beta build that I run started to fail with the following error:
error: lifetime bounds cannot be used in this context
--> src/main.rs:20:63
|
20 | fn send_msg<'a,T,R>(msg :&T) -> R where T: Serialize, for<'d: 'static> R: Deserialize<'d> {
| ^^^^^^^
warning: unnecessary lifetime parameter `'d`
--> src/main.rs:20:59
|
20 | fn send_msg<'a,T,R>(msg :&T) -> R where T: Serialize, for<'d: 'static> R: Deserialize<'d> {
| ^^^^^^^^^^^
|
= help: you can use the `'static` lifetime directly, in place of `'d`
Unfortunately the suggested fix will not work on stable / beta / nightly.
Can anyone comment on the correct way to restrict the generic type R to objects that de-serialize into objects that don’t have a lifetime?