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: IntReprThe 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§
Source§impl 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?))Trait Implementations§
impl Eq for Variant
Source§impl Representable for Variant
impl Representable for Variant
fn representable(&self, by: &Variant) -> RepEquality
impl StructuralPartialEq for Variant
Auto Trait Implementations§
impl !Send for Variant
impl !Sync for Variant
impl Freeze for Variant
impl RefUnwindSafe for Variant
impl Unpin for Variant
impl UnsafeUnpin for Variant
impl UnwindSafe for Variant
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more