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

推荐订阅源

博客园_首页
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
B
Blog
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
月光博客
月光博客
人人都是产品经理
人人都是产品经理
IT之家
IT之家
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
WordPress大学
WordPress大学
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The Cloudflare Blog
C
Check Point 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
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.