1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::collections::HashMap;
use std::option::*;

#[derive(Debug, Clone, PartialEq)]
pub struct Table<T> {
    contents: HashMap<String, T>
}


impl <T: Clone> Table<T> {
    pub fn new() -> Self {
        return Self{contents: HashMap::new()}
    }

    pub fn set(&mut self, name: String, value: T) {
        self.contents.insert(name, value);
    }

    pub fn get(&self, name: String) -> Option<T> {
        self.contents.get(&name).cloned()
    }

    pub fn keys(&self) -> Vec<String> {
        self.contents.iter().map(|(key, _)| key.clone()).collect()
    }

    pub fn values(&self) -> Vec<T> {
        self.contents.iter().map(|(_, value)| value.clone()).collect()
    }
}