Function lrs::intrinsics::discriminant_value

Calculates the discriminant of an enum variant.

Syntax

unsafe extern "rust-intrinsic" fn discriminant_value<T>(v: &T) -> u64

Arguments

NameDescription
v

The variant whose discriminant will be calculated.

Return value

Returns the discriminant value cast to an u64 or 0 if the argument does not have a discriminant value.

Remarks

If the discriminant cannot be represented in an i64, the result is unspecified. Note that it is i64, not u64.

Examples

enum T {
    X,
    Y,
}

assert!(unsafe { discriminant_value(&T::X) } == 0);