What is the type of a type in Rust?

94 points Glum-Psychology-6701 107 comments

Sorry if this sounds like an ill-posed question. Is there a way to model the type of a type in Rust?

To illustrate what I mean,

In Python if you do

`type(2) = int`

but

`type(int) = type`

So `type` is a "superset" of all types and you can generate a custom type at runtime

using `type` as a factory of types. You can create a custom class at run time by doing

`MyClass = type("MyClass", SuperType, some_dict)`, this creates a new class that subtypes `SuperType`, without having to explicitly define a new class.

In Java, you can define a parameter to a function as `Class<T>` and to this you can pass types in as arguments by doing `Integer.class` etc..

I think something similar exists in Zig using `comptime`.

So In Rust is there a way to define a hierarchy of types?