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

推荐订阅源

MyScale Blog
MyScale Blog
F
Fortinet All Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
V
Visual Studio Blog
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
aimingoo的专栏
aimingoo的专栏
小众软件
小众软件
L
LangChain Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
P
Proofpoint News Feed
博客园_首页
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Check Point Blog
Engineering at Meta
Engineering at Meta
Microsoft Azure Blog
Microsoft Azure Blog

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 Lifetime weird case 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
Confusion about struct variance with &mut dyn
foonathan · 2026-04-22 · via The Rust Programming Language Forum - Latest topics
Hello, I'm a bit confused by the following Rust error: Rust Playground trait Trait {} struct Impl; impl Trait for Impl {} struct Holder<'r> { r: &'r mut dyn Trait, } fn static_holder() -> Holder<'static> { Holder{ r: Box::leak(Box::new(Impl)) } } impl<'r> Default for Holder<'r> { fn default() -> Holder<'r> { static_holder() } } I'm getting: error: lifetime may not live long enough --> src/lib.rs:16:9 | 14 | impl<'r> Default for Holder<'r> { | -- lifetime `'r` defined here 15 | fn default() -> Holder<'r> { 16 | static_holder() | ^^^^^^^^^^^^^^^ returning this value requires that `'r` must outlive `'static` | = note: requirement occurs because of the type `Holder<'_>`, which makes the generic argument `'_` invariant = note: the struct `Holder<'r>` is invariant over the parameter `'r` = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance Why is Holder<'r> invariant over r ? The linked nomicon says &'r mut T is covariant over 'r . Why does it work when I remove the dyn Trait and instead hardcode Impl ? Rust Playground Why does it work when I manually deconstruct static_holder and reconstruct a new Holder instance? Rust Playground Thanks! Jonathan 4 posts - 3 participants Read full topic