Crate typedef[stability] [-]  [+] [src]

Fork me on GitHub TypeDef is used to identify and compare types, as well as print their names.

If you do not need readable type name, you should use TypeId. This wrapper re-implements TypeId.

To get a name of a type:

 use typedef::{ TypeDef };

 assert_eq!(TypeDef::name_of::<int>(), "int");

Type can also serve as type identifier and name container:

 use typedef::{ TypeDef };

 let typedef = TypeDef::of::<int>();

 assert!(typedef.is::<int>());
 assert_eq!(typedef.get_str(), "int");

More common usage would be in a generic method:

 use std::fmt::{ Show };
 use typedef::{ TypeDef };

 fn foo<T: 'static + Show>(value: T) -> String {
     format!(
         "the value of {} type is {}",
         TypeDef::of::<T>(),
         value
     )
 }

 fn main() {
     assert_eq!(foo(15i), "the value of int type is 15");
 }

Structs

TypeDef

Create a TypeDef structure to identify a type and to print its name.