惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
Vercel News
Vercel News
Last Week in AI
Last Week in AI
H
Help Net Security
The Cloudflare Blog
L
LangChain Blog
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
I
InfoQ
U
Unit 42
美团技术团队
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 叶小钗
Y
Y Combinator Blog
Hugging Face - Blog
Hugging Face - Blog
A
About on SuperTechFans
宝玉的分享
宝玉的分享
量子位
博客园_首页

The Rust Programming Language Forum - Latest topics

Beginner building a Rust backend framework (AI-assisted) — feedback appreciated C++ to Rust -- Exceptions Re-exporting a trait with a custom derive_macro Gold linker is deprecated Why is using PhantomData valid in this case? Code review for Static Pool Allocator Looking for a pool based allocator Why is this legal? What does it mean for Rustc to run "out of TLS keys"? Using async/await internally with no internal runtime, but exposing a nonblocking poll API — is this a reasonable design? Testing functions that use randomness `cargo-path`: improve coding agents&#39; ability to find Rust documentation Rust task runners Windows - USB device not detected A random rustc-ice-[...].txt file appeared Develop rust where the environment is setup in a docker Undefined Behavior: in-bounds pointer arithmetic failed: attempting to offset pointer by 20 bytes, but got alloc238 which is only 1 byte from the end of the allocation Unbug 0.5 - Runtime debug assertions Is there a tiny error in section 6.2 Reference types? Lifetime woes implementing ratatui::Widget for a reference Rusqlite + Chrono: How do I simplify code to obtain chrono datetime value From OOP to Rust – struggling with code organization and data structure design Way to avoid a self-referential struct Rust RF and audio resources/communities Whyhttp - HTTP mocks that fail where the bug actually is Using tokio channel permits in a tower service Arc::increment_strong_count design question (cross-post) `&T`, `&mut T`, `Pin<&mut T>` and `&Cell<T>`: Ways of Borrowing a `T` Ratatui detect arrow key press and release Feedback about post in medium
Lifetime weird case
@dsal3389 · 2026-04-24 · via The Rust Programming Language Forum - Latest topics
I have some weird case with lifetime, here is a small recreation of the code play.rust-lang.org Rust Playground A browser interface to the Rust compiler to experiment with the language struct Foo(Vec<i32>); impl Foo { fn iter(&self) -> impl Iterator<Item = &i32> { self.0.iter() } } fn main() { let mut x = Foo(vec![1, 2, 3, 4]); if let Some(v) = x.iter().nth(2).map(|i| i.to_string()) { x.0.push(5); } } I was under the impression that x.iter lifetime will not interfere with the if statement block after calling map , since the returned value from map is not a reference, but rust complains that x.0 is already borrowed as immutable this for example works let mut x = Foo(vec![1, 2, 3, 4]); let n = x.iter().nth(2).map(|i| i.to_string()); if let Some(v) = n { x.0.push(5); } even this let mut x = Foo(vec![1, 2, 3, 4]); if let Some(v) = x.0.iter().nth(2).map(|i| i.to_string()) { x.0.push(5); } I don't fully understand why the first example doesn't work...