<story><title>Common Rust Lifetime Misconceptions (2020)</title><url>https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md</url></story><parent_chain></parent_chain><comment><author>MuffinFlavored</author><text>How I bail myself out of Rust lifetime problems as somebody who probably learned Rust the wrong way (by just trying to build stuff as if it were C&amp;#x2F;node.js and run into problems instead of slowing down + reading):&lt;p&gt;1. .clone() &amp;#x2F; .to_owned()&lt;p&gt;1. String -&amp;gt; vs &amp;amp;String&amp;#x2F;&amp;amp;str with &amp;amp; borrow&lt;p&gt;1. lazy_static &amp;#x2F; OnceCell + Lazy &amp;#x2F; OnceLock&lt;p&gt;1. Arc&amp;lt;Mutex&amp;lt;T&amp;gt;&amp;gt; with lots of .lock(). What would start off as like NULL in Java&amp;#x2F;C is Arc&amp;lt;Mutex&amp;lt;Option&amp;lt;T&amp;gt;&amp;gt;&amp;gt; and you have to check if it is .is_none()&lt;p&gt;I think that&amp;#x27;s about it. I rarely introduce a lifetime to a struct&amp;#x2F;impl. I try to avoid it honestly (probably for worse). Arc kind of bails you out of a lot (whether that&amp;#x27;s for good or not I don&amp;#x27;t know).&lt;p&gt;edit: Remembered another. I think it&amp;#x27;s kind of weird&amp;#x2F;too verbose from the compiler &amp;#x2F; borrow checker when you have a primitive like u32 and it&amp;#x27;s borrowed and you had to dereference it or clone it.</text></comment>
<story><title>Common Rust Lifetime Misconceptions (2020)</title><url>https://github.com/pretzelhammer/rust-blog/blob/master/posts/common-rust-lifetime-misconceptions.md</url></story><parent_chain></parent_chain><comment><author>satvikpendem</author><text>I just clone everywhere and write Rust like a high level language. Then, once I need to optimize more, if I ever do (as Rust is many times faster than other languages even with liberal cloning), then I simply go through and remove the clone where needed.</text></comment>