2

I want to run code based on a type parameter T. T can be one of a list of known types.

fn test<T>(t: T){
    // if T = u64 print "Hi"
    // if T = u32 print "Sorry"
}
trent
  • 25,033
  • 7
  • 51
  • 90
Slim Shady
  • 1,045
  • 2
  • 12
  • 38
  • 1
    Let me try that last comment again: [Here's a possible application](http://play.rust-lang.org/?gist=e9295f44151b9c0d3b1cea6b33236b99&version=stable&mode=debug) of the duplicate to your question. You'd presumably want to add additional behavior to the trait, or add bounds to the `test` function, to be able to do much else. – trent May 11 '18 at 01:17

0 Answers0