1use std::fmt;
19use sing_util::TraitCallMessage;
20use serde::{Serialize, Deserialize};
21
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct CallObj {
24 trait_string: Option<String>,
25 fun_string: String,
26 index: usize,
27 data: Vec<String>,
28}
29
30impl CallObj {
32 pub fn new((trait_string, fun_string, index): (Option<String>, String, usize), data: Vec<String>) -> Self {
33 Self{
34 trait_string,
35 fun_string,
36 index,
37 data,
38 }
39 }
40}
41
42impl TraitCallMessage for CallObj {
43 type Representation = String;
44
45 fn get_fun_name(&self) -> String {
46 self.fun_string.clone()
47 }
48
49 fn get_trait_name(&self) -> Option<String> {
50 self.trait_string.clone()
51 }
52
53 fn get_params(&self) -> Vec<Self::Representation> {
54 self.data.clone()
55 }
56
57 fn new_params(&mut self, p: Vec<Self::Representation>) {
58 self.data = p;
59 }
60}
61
62impl fmt::Display for CallObj {
63 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
64 let mut repr = String::new();
65
66 match &self.trait_string {
67 Some(tstr) => {
68 repr.push_str(tstr);
69 repr.push('>');
70 },
71 None => {}
72 }
73
74 repr.push_str(&self.fun_string);
75
76 if self.index != usize::MAX {
77 repr.push('>');
78 repr.push_str(&self.index.to_string());
79 }
80
81 for element in &self.data {
82 repr.push(' ');
83 repr.push_str(element);
84 }
85
86 write!(f, "{}", repr)
87 }
88}