nostr:nprofile1qy2hwumn8ghj7un9d3shjtnddaehgu3wwp6kyqpq4cgq353exzmhdsvqjtmw4dq7fvyleuls8umyrvd5umhr4gtx6asqzk33ng I'm fumbling around a lot with lifetime specifications, and for how often they're needed, the syntax for them seems pretty danged clunky.

I think I want a way to guarantee that this "Chars" points to the same buffer as another "Chars", and I'm doing that by giving them the same lifetime as the object which is processing them, which lets me compile, but feels like I'm not getting this right.

Reply to this note

Please Login to reply.

Discussion

The apostrophe needed in the syntax is confusing to me (...<'a>...)

You can also share buffers by having the two "Chars" point to the same buffer, like so below

-----

struct Chars<'a> {

data: &'a str,

}

fn process_chars<'a>(chars1: Chars<'a>, chars2: Chars<'a>) {

// Both chars1 and chars2 point to the same buffer

println!("Processing: {} and {}", chars1.data, chars2.data);

}

-----

I'm really not good at any of this so please take this with less than two sats of my own worth here. Trying to help both yourself & my own C/C++ to Rust journey 💜

I was also told to pay better attention to the borrow checker's messages too