Generating unique IDs for types at compile time

前端 未结 3 1775
抹茶落季
抹茶落季 2020-12-11 10:01

I want to generate a unique id for every type at compile time. Is this possible in Rust?

So far, I have the following code

//Pseudo code
struct Class         


        
3条回答
  •  伪装坚强ぢ
    2020-12-11 10:39

    std::any::TypeId does something like that:

    use std::any::TypeId;
    
    fn main() {
        let type_id = TypeId::of::();
        println!("{:?}", type_id);
    }
    

    outputs:

    TypeId { t: 4150853580804116396 }
    

提交回复
热议问题