Generate a stable type identifier for rust structs and enums
Use cargo to add this crate to the project dependencies
cargo add stable-typeid
use stable_typeid::*;
fn main() {
let any = MyStruct {
anything: "Hello TypeId".to_string(),
};
foo(&any);
}
fn foo(any: &dyn StableAny) {
if let Some(my_struct) = any.downcast_ref::<MyStruct>() {
println!("{} {}", my_struct.anything, MyStruct::_STABLE_ID);
}
}
#[derive(StableID)]
struct MyStruct {
anything: String,
}