luaur_analysis/type_aliases/
instruction.rs1use crate::records::assign::Assign;
4use crate::records::declare::Declare;
5use crate::records::join::Join;
6use crate::records::refine::Refine;
7
8#[derive(Debug, Clone)]
9pub enum Instruction {
10 Declare(Declare),
11 Assign(Assign),
12 Join(Join),
13 Refine(Refine),
14}
15
16impl Instruction {
17 pub fn index(&self) -> i32 {
19 match self {
20 Instruction::Declare(_) => 0,
21 Instruction::Assign(_) => 1,
22 Instruction::Join(_) => 2,
23 Instruction::Refine(_) => 3,
24 }
25 }
26}
27
28pub trait InstructionMember: Sized {
30 fn get_if(v: &Instruction) -> Option<&Self>;
31 fn get_if_mut(v: &mut Instruction) -> Option<&mut Self>;
32}
33
34impl InstructionMember for Declare {
35 fn get_if(v: &Instruction) -> Option<&Self> {
36 match v {
37 Instruction::Declare(x) => Some(x),
38 _ => None,
39 }
40 }
41 fn get_if_mut(v: &mut Instruction) -> Option<&mut Self> {
42 match v {
43 Instruction::Declare(x) => Some(x),
44 _ => None,
45 }
46 }
47}
48
49impl InstructionMember for Assign {
50 fn get_if(v: &Instruction) -> Option<&Self> {
51 match v {
52 Instruction::Assign(x) => Some(x),
53 _ => None,
54 }
55 }
56 fn get_if_mut(v: &mut Instruction) -> Option<&mut Self> {
57 match v {
58 Instruction::Assign(x) => Some(x),
59 _ => None,
60 }
61 }
62}
63
64impl InstructionMember for Join {
65 fn get_if(v: &Instruction) -> Option<&Self> {
66 match v {
67 Instruction::Join(x) => Some(x),
68 _ => None,
69 }
70 }
71 fn get_if_mut(v: &mut Instruction) -> Option<&mut Self> {
72 match v {
73 Instruction::Join(x) => Some(x),
74 _ => None,
75 }
76 }
77}
78
79impl InstructionMember for Refine {
80 fn get_if(v: &Instruction) -> Option<&Self> {
81 match v {
82 Instruction::Refine(x) => Some(x),
83 _ => None,
84 }
85 }
86 fn get_if_mut(v: &mut Instruction) -> Option<&mut Self> {
87 match v {
88 Instruction::Refine(x) => Some(x),
89 _ => None,
90 }
91 }
92}