Crate typedef [] [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.

Since Rust 1.0, this library can only work on nightly Rust.

To get a name of a type:

use typedef::{ TypeDef };

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

Type can also serve as type identifier and name container:

use typedef::{ TypeDef };

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

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

More common usage would be in a generic method:

use std::any::Any;
use std::fmt;
use typedef::TypeDef;

fn foo<T: Any + fmt::Debug>(value: T) -> String {
    format!(
        "the value of {} type is {:?}",
        TypeDef::of::<T>(),
        value
    )
}

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

Structs

TypeDef

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