Skip to content

Commit 50c4f28

Browse files
committed
Add skeleton of table column types
1 parent d87d4f7 commit 50c4f28

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
pub use sys::bindings;
8484

8585
mod _macros; // Starts w/_ to be sorted at front by rustfmt!
86+
mod table_column;
8687
mod edge_differences;
8788
mod edge_table;
8889
pub mod error;

src/table_column.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#[derive(Clone, Debug)]
2+
#[repr(transparent)]
3+
pub struct TableColumn<'table, T>(&'table [T]);
4+
5+
#[derive(Debug)]
6+
#[repr(transparent)]
7+
pub struct MutableTableColumn<'table, T>(&'table mut [T]);
8+
9+
// NOT part of tskit's public API
10+
pub fn new_table_column<T>(data: &[T]) -> TableColumn<'_, T> {
11+
TableColumn(data)
12+
}
13+
14+
// NOT part of tskit's public API
15+
pub fn new_mutable_table_column<T>(data: &mut [T]) -> MutableTableColumn<'_, T> {
16+
MutableTableColumn(data)
17+
}
18+
19+
impl<T> std::convert::AsRef<[T]> for TableColumn<'_, T> {
20+
fn as_ref(&self) -> &[T] {
21+
self.0
22+
}
23+
}
24+
25+
impl<T> std::convert::AsRef<[T]> for MutableTableColumn<'_, T> {
26+
fn as_ref(&self) -> &[T] {
27+
self.0
28+
}
29+
}
30+
31+
impl<T> std::convert::AsMut<[T]> for MutableTableColumn<'_, T> {
32+
fn as_mut(&mut self) -> &mut [T] {
33+
self.0
34+
}
35+
}
36+
37+
impl<T> std::ops::Index<usize> for TableColumn<'_, T> {
38+
type Output = T;
39+
fn index(&self, index: usize) -> &Self::Output {
40+
&self.0[index]
41+
}
42+
}
43+
44+
impl<T> std::ops::Index<usize> for MutableTableColumn<'_, T> {
45+
type Output = T;
46+
fn index(&self, index: usize) -> &Self::Output {
47+
&self.0[index]
48+
}
49+
}
50+
51+
impl<T> std::ops::IndexMut<usize> for MutableTableColumn<'_, T> {
52+
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
53+
self.0.index_mut(index)
54+
}
55+
}

0 commit comments

Comments
 (0)