0

I have some code which will print the TypeId of a variable passed in.

fn typeid<T: std::any::Any>(_: &T) {
    println!("{:?}", std::any::Type::of::<T>());
}

This works, but gives me a numeric id for the type. Is there a way to output the actual type? For example 1716249077420000607 is f64 (IIRC) or do I need to create a physical list (possibly as an enum) and output that value as part of a match construct?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Nodoid
  • 1,449
  • 3
  • 24
  • 42
  • I've seen that answer but get_tydesc for some reason caused the compiler to bork so wasn't sure if it was me, the call was deprecated, or something else. – Nodoid Apr 30 '16 at 08:06
  • The second answer works https://play.rust-lang.org/?gist=de059307b1bc12ee0bd713da0284f50e&version=nightly&backtrace=0 – malbarbo Apr 30 '16 at 12:57
  • `1716249077420000607` would be unlikely to be a `f64`. Maybe you meant `u64`? – Shepmaster Apr 30 '16 at 13:42
  • @malbarbo - any way of getting that example to work on the stable branch? – Nodoid Apr 30 '16 at 16:08

0 Answers0