Crates.io | stable-typeid |
lib.rs | stable-typeid |
version | 0.0.1 |
source | src |
created_at | 2024-01-17 07:44:08.705522 |
updated_at | 2024-01-17 07:44:08.705522 |
description | Generate a stable type identifier for rust structs and enums |
homepage | |
repository | https://github.com/BERADQ/stable-typeid |
max_upload_size | |
id | 1102567 |
size | 5,335 |
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,
}