vmi_utils/bridge/
response.rs

1/// A response from the bridge.
2#[derive(Debug)]
3pub struct BridgeResponse<T = ()> {
4    value1: Option<u64>,
5    value2: Option<u64>,
6    value3: Option<u64>,
7    value4: Option<u64>,
8    result: Option<T>,
9}
10
11impl<T> Default for BridgeResponse<T> {
12    fn default() -> Self {
13        Self {
14            value1: None,
15            value2: None,
16            value3: None,
17            value4: None,
18            result: None,
19        }
20    }
21}
22
23impl<T> BridgeResponse<T> {
24    /// Creates a new response with the given value.
25    pub fn new(value1: u64) -> Self {
26        Self {
27            value1: Some(value1),
28            value2: None,
29            value3: None,
30            value4: None,
31            result: None,
32        }
33    }
34
35    /// Returns the first value of the response.
36    pub fn value1(&self) -> Option<u64> {
37        self.value1
38    }
39
40    /// Returns the second value of the response.
41    pub fn value2(&self) -> Option<u64> {
42        self.value2
43    }
44
45    /// Returns the third value of the response.
46    pub fn value3(&self) -> Option<u64> {
47        self.value3
48    }
49
50    /// Returns the fourth value of the response.
51    pub fn value4(&self) -> Option<u64> {
52        self.value4
53    }
54
55    /// Returns the result of the response.
56    pub fn result(&self) -> Option<&T> {
57        self.result.as_ref()
58    }
59
60    /// Converts the response into a result.
61    pub fn into_result(self) -> Option<T> {
62        self.result
63    }
64
65    /// Sets the first value of the response.
66    pub fn with_value1(self, value1: u64) -> Self {
67        Self {
68            value1: Some(value1),
69            ..self
70        }
71    }
72
73    /// Sets the second value of the response.
74    pub fn with_value2(self, value2: u64) -> Self {
75        Self {
76            value2: Some(value2),
77            ..self
78        }
79    }
80
81    /// Sets the third value of the response.
82    pub fn with_value3(self, value3: u64) -> Self {
83        Self {
84            value3: Some(value3),
85            ..self
86        }
87    }
88
89    /// Sets the fourth value of the response.
90    pub fn with_value4(self, value4: u64) -> Self {
91        Self {
92            value4: Some(value4),
93            ..self
94        }
95    }
96
97    /// Sets the result of the response.
98    pub fn with_result(self, result: T) -> Self {
99        Self {
100            result: Some(result),
101            ..self
102        }
103    }
104}