gremlin_client/process/traversal/
bytecode.rs1use crate::GValue;
2
3#[derive(Debug, PartialEq, Clone)]
4pub struct Bytecode {
5 source_instructions: Vec<Instruction>,
6 step_instructions: Vec<Instruction>,
7}
8
9impl Default for Bytecode {
10 fn default() -> Bytecode {
11 Bytecode {
12 source_instructions: vec![],
13 step_instructions: vec![],
14 }
15 }
16}
17impl Bytecode {
18 pub fn new() -> Bytecode {
19 Default::default()
20 }
21
22 pub fn add_source(&mut self, source_name: String, args: Vec<GValue>) {
23 self.source_instructions
24 .push(Instruction::new(source_name, args));
25 }
26 pub fn add_step(&mut self, step_name: String, args: Vec<GValue>) {
27 self.step_instructions
28 .push(Instruction::new(step_name, args));
29 }
30
31 pub fn steps(&self) -> &Vec<Instruction> {
32 &self.step_instructions
33 }
34
35 pub fn sources(&self) -> &Vec<Instruction> {
36 &self.source_instructions
37 }
38}
39
40lazy_static! {
41 pub static ref WRITE_OPERATORS: Vec<&'static str> =
42 vec!["addV", "property", "addE", "from", "to", "drop"];
43}
44
45#[derive(Debug, PartialEq, Clone)]
46pub struct Instruction {
47 operator: String,
48 args: Vec<GValue>,
49}
50
51impl Instruction {
52 pub fn new(operator: String, args: Vec<GValue>) -> Instruction {
53 Instruction { operator, args }
54 }
55
56 pub fn operator(&self) -> &String {
57 &self.operator
58 }
59
60 pub fn args(&self) -> &Vec<GValue> {
61 &self.args
62 }
63}