Skip to content

Commit 00d9b32

Browse files
committed
move
1 parent 337c95f commit 00d9b32

File tree

4 files changed

+58
-56
lines changed

4 files changed

+58
-56
lines changed

src/edge_table.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,19 +358,19 @@ impl EdgeTable {
358358
/// Get the child column as a slice of the underlying integer type
359359
=> child, child_slice_raw, ll_bindings::tsk_id_t);
360360

361-
pub fn parent_column(&self) -> impl crate::table_column::TableColumn<EdgeId, NodeId> + '_ {
361+
pub fn parent_column(&self) -> impl crate::TableColumn<EdgeId, NodeId> + '_ {
362362
crate::table_column::OpaqueTableColumn(self.parent_slice())
363363
}
364364

365-
pub fn child_column(&self) -> impl crate::table_column::TableColumn<EdgeId, NodeId> + '_ {
365+
pub fn child_column(&self) -> impl crate::TableColumn<EdgeId, NodeId> + '_ {
366366
crate::table_column::OpaqueTableColumn(self.child_slice())
367367
}
368368

369-
pub fn left_column(&self) -> impl crate::table_column::TableColumn<EdgeId, Position> + '_ {
369+
pub fn left_column(&self) -> impl crate::TableColumn<EdgeId, Position> + '_ {
370370
crate::table_column::OpaqueTableColumn(self.left_slice())
371371
}
372372

373-
pub fn right_column(&self) -> impl crate::table_column::TableColumn<EdgeId, Position> + '_ {
373+
pub fn right_column(&self) -> impl crate::TableColumn<EdgeId, Position> + '_ {
374374
crate::table_column::OpaqueTableColumn(self.right_slice())
375375
}
376376

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ pub use site_table::{SiteTable, SiteTableRow};
117117
pub use sys::flags::*;
118118
pub use sys::NodeTraversalOrder;
119119
pub use table_collection::TableCollection;
120-
pub use table_column::TableColumn;
120+
pub use traits::TableColumn;
121121
pub use traits::IndividualLocation;
122122
pub use traits::IndividualParents;
123123
pub use trees::{Tree, TreeSequence};

src/table_column.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ impl<T> std::ops::Index<usize> for OpaqueTableColumn<'_, T> {
1010
}
1111
}
1212

13-
mod private {
14-
pub trait NewTypeMarker: TryInto<usize, Error = crate::TskitError> {}
15-
pub trait TableColumnMarker {}
16-
}
17-
18-
impl private::NewTypeMarker for crate::EdgeId {}
19-
impl private::NewTypeMarker for crate::NodeId {}
2013

2114
impl<T> std::ops::Index<crate::SizeType> for OpaqueTableColumn<'_, T> {
2215
type Output = T;
@@ -26,47 +19,3 @@ impl<T> std::ops::Index<crate::SizeType> for OpaqueTableColumn<'_, T> {
2619
}
2720
}
2821

29-
impl<I, T> std::ops::Index<I> for OpaqueTableColumn<'_, T>
30-
where
31-
I: private::NewTypeMarker,
32-
{
33-
type Output = T;
34-
fn index(&self, index: I) -> &Self::Output {
35-
&self.0[index.try_into().unwrap()]
36-
}
37-
}
38-
39-
pub trait TableColumn<I, T>:
40-
std::ops::Index<I, Output = T>
41-
+ std::ops::Index<usize, Output = T>
42-
+ std::ops::Index<crate::SizeType, Output = T>
43-
+ private::TableColumnMarker
44-
{
45-
fn as_slice(&self) -> &[T];
46-
fn get(&self, at: usize) -> Option<&T>;
47-
fn get_with_id(&self, at: I) -> Option<&T>;
48-
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T>;
49-
}
50-
51-
impl<T> private::TableColumnMarker for OpaqueTableColumn<'_, T> {}
52-
53-
impl<I, T> TableColumn<I, T> for OpaqueTableColumn<'_, T>
54-
where
55-
I: private::NewTypeMarker,
56-
{
57-
fn as_slice(&self) -> &[T] {
58-
self.0
59-
}
60-
61-
fn get(&self, at: usize) -> Option<&T> {
62-
self.0.get(at)
63-
}
64-
65-
fn get_with_id(&self, at: I) -> Option<&T> {
66-
self.0.get(at.try_into().unwrap())
67-
}
68-
69-
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T> {
70-
self.0.get(usize::try_from(at).unwrap())
71-
}
72-
}

src/traits.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,56 @@ impl_individual_parents!(
119119
);
120120
impl_individual_parents!(N, usize, &[crate::IndividualId; N], self, self.as_slice());
121121
impl_individual_parents!(N, usize, [crate::IndividualId; N], self, self.as_slice());
122+
123+
mod private {
124+
pub trait NewTypeMarker: TryInto<usize, Error = crate::TskitError> {}
125+
pub trait TableColumnMarker {}
126+
}
127+
128+
impl private::NewTypeMarker for crate::EdgeId {}
129+
impl private::NewTypeMarker for crate::NodeId {}
130+
131+
pub trait TableColumn<I, T>:
132+
std::ops::Index<I, Output = T>
133+
+ std::ops::Index<usize, Output = T>
134+
+ std::ops::Index<crate::SizeType, Output = T>
135+
+ private::TableColumnMarker
136+
{
137+
fn as_slice(&self) -> &[T];
138+
fn get(&self, at: usize) -> Option<&T>;
139+
fn get_with_id(&self, at: I) -> Option<&T>;
140+
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T>;
141+
}
142+
143+
impl<T> private::TableColumnMarker for crate::table_column::OpaqueTableColumn<'_, T> {}
144+
145+
impl<I, T> std::ops::Index<I> for crate::table_column::OpaqueTableColumn<'_, T>
146+
where
147+
I: private::NewTypeMarker,
148+
{
149+
type Output = T;
150+
fn index(&self, index: I) -> &Self::Output {
151+
&self.0[index.try_into().unwrap()]
152+
}
153+
}
154+
155+
impl<I, T> TableColumn<I, T> for crate::table_column::OpaqueTableColumn<'_, T>
156+
where
157+
I: private::NewTypeMarker,
158+
{
159+
fn as_slice(&self) -> &[T] {
160+
self.0
161+
}
162+
163+
fn get(&self, at: usize) -> Option<&T> {
164+
self.0.get(at)
165+
}
166+
167+
fn get_with_id(&self, at: I) -> Option<&T> {
168+
self.0.get(at.try_into().unwrap())
169+
}
170+
171+
fn get_with_size_type(&self, at: crate::SizeType) -> Option<&T> {
172+
self.0.get(usize::try_from(at).unwrap())
173+
}
174+
}

0 commit comments

Comments
 (0)