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
sourceimpl Variant
impl Variant
sourcepub fn as_expected(&self) -> Option<(Option<&TypeRef>, Option<&TypeRef>)>
pub fn as_expected(&self) -> Option<(Option<&TypeRef>, Option<&TypeRef>)>
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?))
sourceimpl Variant
impl Variant
pub fn payload_offset(&self) -> usize
Trait Implementations
sourceimpl Representable for Variant
impl Representable for Variant
fn representable(&self, by: &Self) -> RepEquality
impl Eq for Variant
impl StructuralEq for Variant
impl StructuralPartialEq for Variant
Auto Trait Implementations
impl RefUnwindSafe for Variant
impl !Send for Variant
impl !Sync for Variant
impl Unpin for Variant
impl UnwindSafe for Variant
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more