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

推荐订阅源

Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
博客园 - 司徒正美
美团技术团队
Vercel News
Vercel News
IT之家
IT之家
U
Unit 42
Y
Y Combinator Blog
罗磊的独立博客
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
Jina AI
Jina AI
V
Visual Studio Blog
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
博客园 - 叶小钗
A
About on SuperTechFans
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
B
Blog RSS Feed

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
Why there is no downcast method
BORSXN · 2026-04-17 · via The Rust Programming Language Forum - Latest topics

April 17, 2026, 4:18am 1

use std::{any::Any, collections::HashMap};

fn main() {
    println!("Hello, world!");
    let s = SHM::new();
    s.get(&Screen::Login).unwrap().downcast_ref::<Login>();
}

trait Page: Any {}
struct Login;
impl Page for Login {}
type SHM = HashMap<Screen, Box<dyn Page>>;
#[derive(Debug, Hash, PartialEq, Eq)]
enum Screen {
    Login,
}

    Checking tdowncast v0.1.0 (E:\Coding\Code\Rust\tdowncast)
error[E0599]: no method named `downcast_ref` found for reference `&Box<dyn Page>` in the current scope
 --> src\main.rs:6:36
  |
6 |     s.get(&Screen::Login).unwrap().downcast_ref::<Login>();
  |                                    ^^^^^^^^^^^^
  |
help: there is a method `as_ref` with a similar name
  |
6 -     s.get(&Screen::Login).unwrap().downcast_ref::<Login>();
6 +     s.get(&Screen::Login).unwrap().as_ref::<Login>();
  |

For more information about this error, try `rustc --explain E0599`.

You need to implement Page for Screen.

After Screen implements Page, take a look at this

quinedot April 17, 2026, 4:29am 3

Ignoring dyn compatibility, if it were a method of the Any trait, you would be calling downcast_ref on Box<dyn Page>, which could not succeed for a target other than itself.