I don't want to check whether a type has a certain trait but I would like to be able to differentiate between, e.g. a struct and an integer. Since both a struct and an integer can implement the same trait, I don't know how I could tell them apart.
The reason that I want to do this is because I am using serde_json to convert a generic type to JSON but I only want it to become a JSON Object
(which happens when it is a struct) but it should not convert to anything else (like an JSON I64
). Since both structs and integers can implement the Serialize
trait, there is no way to tell them apart.
Currently, I let the process panic because it is not an error it could recover from, but since I could potentially know this at compile time, I am wondering whether there is any mechanism to determine the type at the compile stage.
I would like to know how I can tell types apart by their "kind" and not by their traits.