scrambledb/table.rs
1//! ## Tables and Data Types
2//! The `ScrambleDB` protocol provides conversions between types of data
3//! tables that are differentiated by their structure and contents.
4
5#[derive(Debug, Clone)]
6pub struct Table<T> {
7 identifier: String,
8 data: Vec<T>,
9}
10
11impl<T> Table<T> {
12 /// Create a new table.
13 pub fn new(identifier: String, data: Vec<T>) -> Self {
14 Self { identifier, data }
15 }
16
17 /// Get the identifier (name) of this table.
18 pub fn identifier(&self) -> &str {
19 &self.identifier
20 }
21
22 /// Get the table entries.
23 pub fn data(&self) -> &[T] {
24 self.data.as_ref()
25 }
26
27 /// Sort the table by its handles.
28 pub fn sort(&mut self)
29 where
30 T: Ord,
31 {
32 self.data.sort()
33 }
34}