Guest User

Untitled

a guest
Jul 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. use std::any::Any;
  2. use std::fmt::Debug;
  3.  
  4. use std::mem::size_of_val;
  5.  
  6. fn main() {
  7. const n: i32 = 35;
  8. let to: &'static dyn Debug = &n;
  9. let any: &Any = &to;
  10. if let Some(to2) = any.downcast_ref::<&dyn Debug>() {
  11. println!("{:?}", to2);
  12. println!(
  13. "size of n is {}, size of to2 is {}",
  14. size_of_val(&n),
  15. size_of_val(&to2)
  16. );
  17. } else {
  18. println!("Nope");
  19. }
  20. }
Add Comment
Please, Sign In to add comment