#TypeId

3 messages · Page 1 of 1 (latest)

rose elk
#

is it guaranteed that TypeId of SomeEnum::SomeTupleLikeVariant (which is a function) will be the same no matter where in the code the caller is?

// example
fn id<A, B, F: Fn(A) -> B + 'static>(_func: &F) -> TypeId {
    TypeId::of::<F>()
}

enum Stat {
    Life(i64),
    Mana(i64)
}

assert!(id(&Stat::Life) != id(&Stat::Mana));
rose elk
#

assuming they are not coerced to fn ptr at any time like:

let a: fn(_) -> _ = Stat::Life;
let b: fn(_) -> _ = Stat::Mana;

because then

assert!(id(&a) == id(&b));
ionic parrot
#

The TypeId is always the same for the same type