1#[derive(Debug, Clone)]
2pub struct Data {
3 pub data: Vec<(&'static str, &'static str)>,
4}
5
6impl Data {
7 pub fn new() -> Self {
8 Self { data: Vec::new() }
9 }
10
11 pub fn add(mut self, key: &'static str, value: &'static str) -> Self {
12 self.data.push((key, value));
13
14 self
15 }
16
17 pub fn get(&self, key: &'static str) -> Option<&'static str> {
18 for (k, v) in &self.data {
19 if k == &key {
20 return Some(v);
21 }
22 }
23
24 None
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn data_new() {
34 let data: Data = Data::new();
35
36 assert_eq!(data.data, Vec::new());
37 }
38
39 #[test]
40 fn data_add() {
41 let data: Data = Data::new().add("key", "value");
42
43 assert_eq!(data.data, vec![("key", "value")]);
44 }
45
46 #[test]
47 fn data_get() {
48 let data: Data = Data::new().add("key", "value");
49
50 assert_eq!(data.get("key"), Some("value"));
51 assert_eq!(data.get("key2"), None);
52 }
53}