Hello! Help to deal with such a question.
I make two structures, one FullJson , the second BodyJson . FullJson includes BodyJson as one of its fields. And then in the loop function 10 instances of FullJson are created and transferred somewhere further.
At compilation, the error of the “ expected lifetime parameter ” got out ... It was useful to look at the lifetime in the plant, stumbled on <'a>, <' b>, like the error had disappeared. But I try to understand how this thing works ...
Below is the code that eventually turned out.
Do I understand correctly that having created BodyJson <'a> and FullJson <' b>, I marked their lifetime and that BodyJson <'b> has become FullJson's lifetime ? And such a question is why the compiler has requested that I do this: body: & 'b BodyJson <' b> , i.e. indicated two times ' b ?
Link to gist https://gist.github.com/rogerwilcos/70a78af82713779f1574d030f6013c52
#[macro_use] extern crate serde_derive; extern crate serde; #[macro_use] extern crate serde_json; extern crate exonum; use exonum::crypto::{self, CryptoHash, Hash, PublicKey, SecretKey}; #[derive(Serialize, Debug)] struct BodyJson<'a> { pub_key: &'a PublicKey, act_id: &'a str, form_act_id: &'a str, block: &'a str, status: &'a str, } #[derive(Serialize, Debug)] struct FullJson<'b> { network_id: &'b str, protocol_version: &'b str, service_id: &'b str, message_id: &'b str, signature: exonum::crypto::SecretKey, body: &'b BodyJson<'b>, }