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`.
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.