#stable #type-id #structs #identifier #generate

yanked stable-typeid

Generate a stable type identifier for rust structs and enums

1 unstable release

0.0.1 Jan 17, 2024

#21 in #type-id

Custom license

5KB
99 lines

Stable TypeId

Generate a stable type identifier for rust structs and enums

Usage

Use cargo to add this crate to the project dependencies

  cargo add stable-typeid

Demo

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,
}

Dependencies

~215–650KB
~16K SLoC