Lifetime issue with deserialization

Hi Everyone, I've been tinkering with rust for about a year now and have done a bunch of simple little things with it, but now I'm trying to do something a little more involved and ran into an issue with Lifetimes that I can't make any sense out of. I've tried following the advice of the compiler, but that just leads me in circles.

I've put a simple sample project up here: https://github.com/kasper22-bb/rust-pulsar-sample

The goal here is fairly simple. I have an handful of fields that all pulsar messages are going to be expected to carry plus a data field that carries another struct.

When I tried to build I get:

    error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements
--> src/lib.rs:30:32
|
30 |         serde_json::from_slice(&payload.data)
|                                ^^^^^^^^^^^^^
|
note: first, the lifetime cannot outlive the anonymous lifetime #1 defined on the method body at 29:5...
  --> src/lib.rs:29:5
   |
29 | /     fn deserialize_message(payload: &Payload) -> Self::Output {
30 | |         serde_json::from_slice(&payload.data)
31 | |     }
   | |_____^
note: ...so that reference does not outlive borrowed content
  --> src/lib.rs:30:32
   |
30 |         serde_json::from_slice(&payload.data)
   |                                ^^^^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime `'de` as defined on the impl at 24:6...
  --> src/lib.rs:24:6
   |
24 | impl<'de: 'a, 'a, T> DeserializeMessage for PulsarMessageWrapper<T>
   |      ^^^
note: ...so that the types are compatible
  --> src/lib.rs:30:9
   |
30 |         serde_json::from_slice(&payload.data)
   |         ^^^^^^^^^^^^^^^^^^^^^^
   = note: expected  `_::_serde::Deserialize<'_>`
              found  `_::_serde::Deserialize<'de>`

The 'de' lifetime is based on information I found here: Deserializer lifetimes · Serde

I'm I approaching the error incorrectly or the solution not the right approach for Rust?

Thanks for any advice or feedback

If you want to be taken seriously, please take the time to format your post as described in the pinned post. Also, edit your post. Do not make a new one.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.