|
| 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