pub struct Variant {
    pub tag_repr: IntRepr,
    pub cases: Vec<Case>,
}
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 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.