Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::any::Any;
- use std::fmt::Debug;
- use std::mem::size_of_val;
- fn main() {
- const n: i32 = 35;
- let to: &'static dyn Debug = &n;
- let any: &Any = &to;
- if let Some(to2) = any.downcast_ref::<&dyn Debug>() {
- println!("{:?}", to2);
- println!(
- "size of n is {}, size of to2 is {}",
- size_of_val(&n),
- size_of_val(&to2)
- );
- } else {
- println!("Nope");
- }
- }
Add Comment
Please, Sign In to add comment