Skip to main content

luaur_analysis/type_aliases/
variant.rs

1//! Source: `Analysis/include/Luau/Def.h:66` (hand-ported)
2use crate::records::cell::Cell;
3use crate::records::phi::Phi;
4use luaur_common::records::variant::Variant2;
5
6// Def::V — the definition variant. (Previous content here was a copy of an
7// unrelated Bound/Error/Value variant: wrong-content alias, fixed 06-12.)
8pub type Variant = Variant2<Cell, Phi>;
9
10/// `get_if<T>(&v)` over this variant, the Rust shape of C++ overload-on-T.
11pub trait VariantMember: Sized {
12    fn get_if(v: &Variant) -> Option<&Self>;
13    fn get_if_mut(v: &mut Variant) -> Option<&mut Self>;
14}
15
16impl VariantMember for Cell {
17    fn get_if(v: &Variant) -> Option<&Self> {
18        v.get_if_0()
19    }
20    fn get_if_mut(v: &mut Variant) -> Option<&mut Self> {
21        v.get_if_0_mut()
22    }
23}
24
25impl VariantMember for Phi {
26    fn get_if(v: &Variant) -> Option<&Self> {
27        v.get_if_1()
28    }
29    fn get_if_mut(v: &mut Variant) -> Option<&mut Self> {
30        v.get_if_1_mut()
31    }
32}