Struct witnext::Variant [−][src]
Expand description
A type which represents how values can be one of a set of possible cases.
This type maps to an enum
in languages like Rust, but doesn’t have an
equivalent in languages like JS or C. The closest analog in C is a tagged
union, but a Variant
is always consistent whereas a tagged union in C
could be mis-tagged or such.
Variants are used to represent one of a possible set of types. For example
an enum-like variant, a result that is either success or failure, or even a
simple bool
. Variants are primarily used heavily with various kinds of
shorthands in the *.witx
format to represent idioms in languages.
Fields
tag_repr: IntRepr
The bit representation of the width of this variant’s tag when the variant is stored in memory.
cases: Vec<Case>
The possible cases that values of this variant type can take.
Implementations
If this variant looks like an option
shorthand, return the type
associated with option.
Only matches variants fo the form:
(variant
(case "none")
(case "some" ty))
If this variant looks like an expected
shorthand, return the ok/err
types associated with this result.
Only matches variants fo the form:
(variant
(case "ok" ok?)
(case "err" err?))
Returns whether this variant type is “bool-like” meaning that it matches this type:
(variant
(case "false")
(case "true"))
Returns whether this variant type is “enum-like” meaning that all of its cases have no payload associated with them.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Variant
impl !UnwindSafe for Variant
Blanket Implementations
Mutably borrows from an owned value. Read more