@@ -61,21 +61,26 @@ For any given type, `discriminant_value` will return a `u64` value. The values r
61
61
specified:
62
62
63
63
* ** Non-Enum Type** : Always 0
64
- * ** Enum Type** : A value that uniquely identifies that variant within its type. I.E. for a given
65
- enum typem ` E ` , and two values of type ` E ` , ` a ` and ` b ` , the expression `discriminant_value(a) ==
66
- discriminant_value(b)` is true iff ` a` and ` b` are the same variant. Two values of different types
67
- may return the same discriminant value.
64
+ * ** C-Like Enum Type** : If no variants have fields, then the enum is considered "C-Like". The user
65
+ is able to specify discriminant values in this case, and the return value would be equivalent to
66
+ the result of casting the variant to a ` u64 ` .
67
+ * ** ADT Enum Type** : If any variant has a field, then the enum is conidered to be an "ADT" enum. The
68
+ user is not able to specify the discriminant value in this case. The precise values are
69
+ unspecified, but have the following characteristics:
68
70
69
- The reason for this specification is to allow flexibilty in usage of the intrinsic without
70
- compromising our ability to change the representation at will.
71
+ * The value returned for the same variant of the same enum type will compare as
72
+ equal. I.E. ` discriminant_value(v) == discriminant_value(v) ` .
73
+ * Two values returned for different variants will compare as unequal relative to their respective
74
+ listed positions. That means that if variant ` A ` is listed before variant ` B ` , then
75
+ ` discriminant_value(A) < discriminant_value(B) ` .
76
+
77
+ Note the returned values for two differently-typed variants may compare in any way.
71
78
72
79
# Drawbacks
73
80
74
81
* Potentially exposes implementation details. However, relying the specific values returned from
75
82
` discriminant_value ` should be considered bad practice, as the intrinsic provides no such guarantee.
76
83
77
- * Does not allow for the value to be used as part of ordering.
78
-
79
84
* Allows non-enum types to be provided. This may be unexpected by some users.
80
85
81
86
# Alternatives
0 commit comments