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
31
32
33
34
//! ## Tables and Data Types
//! The `ScrambleDB` protocol provides conversions between types of data
//! tables that are differentiated by their structure and contents.

#[derive(Debug, Clone)]
pub struct Table<T> {
    identifier: String,
    data: Vec<T>,
}

impl<T> Table<T> {
    /// Create a new table.
    pub fn new(identifier: String, data: Vec<T>) -> Self {
        Self { identifier, data }
    }

    /// Get the identifier (name) of this table.
    pub fn identifier(&self) -> &str {
        &self.identifier
    }

    /// Get the table entries.
    pub fn data(&self) -> &[T] {
        self.data.as_ref()
    }

    /// Sort the table by its handles.
    pub fn sort(&mut self)
    where
        T: Ord,
    {
        self.data.sort()
    }
}