TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Common Rust Lifetime Misconceptions

178 pointsby donmccalmost 5 years ago

5 comments

est31almost 5 years ago
&gt; T only contains owned types<p>I&#x27;d say this is true, because I consider &amp;mut T and &amp;T to be owned types in their own right. They own a pointer. I can cast them to raw pointers. &amp;T impl&#x27;s Copy even if T doesn&#x27;t. <a href="https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;1.43.1&#x2F;src&#x2F;core&#x2F;marker.rs.html#794" rel="nofollow">https:&#x2F;&#x2F;doc.rust-lang.org&#x2F;1.43.1&#x2F;src&#x2F;core&#x2F;marker.rs.html#794</a><p>Otherwise, the compilation is great.
评论 #23282328 未加载
评论 #23282127 未加载
antplsalmost 5 years ago
Reading this document suddenly made learning Rust a lot scarier, and also increases my respect to Rust developers (people writing programs in Rust). It kind of shows that increased safety doesn&#x27;t come for free.
评论 #23282906 未加载
评论 #23281930 未加载
评论 #23281723 未加载
评论 #23282462 未加载
评论 #23284064 未加载
评论 #23283088 未加载
评论 #23285098 未加载
评论 #23282189 未加载
评论 #23290380 未加载
评论 #23282963 未加载
评论 #23282341 未加载
k__almost 5 years ago
Coming from JS it was rather counterintuitive for me that a function would &quot;own&quot; a value even if it was ran synchronously and finished.<p>Also, the whole &#x27;move&#x27; terminology sounded to me like Rust would move memory around, but it usually referred to the move of ownership. Also &#x27;consume&#x27; didn&#x27;t make no sense to me. &quot;into_iter consumes a vector&quot; what does it mean? Where does the vector go?<p>The most valuable info I got about lifetimes was: references&#x2F;borrowing is usually what you want, so always throw in a &amp;.
评论 #23283451 未加载
评论 #23283226 未加载
评论 #23283661 未加载
评论 #23282940 未加载
评论 #23283252 未加载
joaomorenoalmost 5 years ago
This is a fantastic article, please someone bump this up to the Rust book.
charlieflowersalmost 5 years ago
This is an EXCELLENT article. Point # 8 should be directly in the Rust book.<p>&quot;Once a variable is bounded by a lifetime it is bounded by that lifetime forever. The lifetime of a variable can only shrink, and all the shrinkage is determined at compile-time.&quot;