Rust noob asks: lifetime of a reference in a struct

Notice that NaiveDate is Copy: chrono::naive::NaiveDate - Rust

That means it's trivial to copy around, so there's generally no value in storing a reference to it, since you could just have a copy instead.

If you're used to other languages where everything is references you might just be used to having references to things, but in Rust make sure you really need them. Often a simple .clone() will make your life way easier without material downside -- and it might even make things smaller and faster.

To re-use one of my favourite recent lines from this forum,

3 Likes