11use crate :: bindings as ll_bindings;
22use crate :: metadata;
3- use crate :: NodeId ;
43use crate :: { tsk_id_t, tsk_size_t, TskitError } ;
4+ use crate :: { MutationId , NodeId , SiteId } ;
55
66/// Row of a [`MutationTable`]
77pub struct MutationTableRow {
8- pub id : tsk_id_t ,
9- pub site : tsk_id_t ,
8+ pub id : MutationId ,
9+ pub site : SiteId ,
1010 pub node : NodeId ,
11- pub parent : tsk_id_t ,
11+ pub parent : MutationId ,
1212 pub time : f64 ,
1313 pub derived_state : Option < Vec < u8 > > ,
1414 pub metadata : Option < Vec < u8 > > ,
@@ -29,7 +29,7 @@ impl PartialEq for MutationTableRow {
2929fn make_mutation_table_row ( table : & MutationTable , pos : tsk_id_t ) -> Option < MutationTableRow > {
3030 if pos < table. num_rows ( ) as tsk_id_t {
3131 let rv = MutationTableRow {
32- id : pos,
32+ id : pos. into ( ) ,
3333 site : table. site ( pos) . unwrap ( ) ,
3434 node : table. node ( pos) . unwrap ( ) ,
3535 parent : table. parent ( pos) . unwrap ( ) ,
@@ -90,8 +90,8 @@ impl<'a> MutationTable<'a> {
9090 ///
9191 /// Will return [``IndexError``](crate::TskitError::IndexError)
9292 /// if ``row`` is out of range.
93- pub fn site ( & ' a self , row : tsk_id_t ) -> Result < tsk_id_t , TskitError > {
94- unsafe_tsk_column_access ! ( row, 0 , self . num_rows( ) , self . table_. site)
93+ pub fn site < M : Into < MutationId > + Copy > ( & ' a self , row : M ) -> Result < SiteId , TskitError > {
94+ unsafe_tsk_column_access ! ( row. into ( ) . 0 , 0 , self . num_rows( ) , self . table_. site, SiteId )
9595 }
9696
9797 /// Return the ``node`` value from row ``row`` of the table.
@@ -100,8 +100,8 @@ impl<'a> MutationTable<'a> {
100100 ///
101101 /// Will return [``IndexError``](crate::TskitError::IndexError)
102102 /// if ``row`` is out of range.
103- pub fn node ( & ' a self , row : tsk_id_t ) -> Result < NodeId , TskitError > {
104- unsafe_tsk_column_access ! ( row, 0 , self . num_rows( ) , self . table_. node, NodeId )
103+ pub fn node < M : Into < MutationId > + Copy > ( & ' a self , row : M ) -> Result < NodeId , TskitError > {
104+ unsafe_tsk_column_access ! ( row. into ( ) . 0 , 0 , self . num_rows( ) , self . table_. node, NodeId )
105105 }
106106
107107 /// Return the ``parent`` value from row ``row`` of the table.
@@ -110,8 +110,14 @@ impl<'a> MutationTable<'a> {
110110 ///
111111 /// Will return [``IndexError``](crate::TskitError::IndexError)
112112 /// if ``row`` is out of range.
113- pub fn parent ( & ' a self , row : tsk_id_t ) -> Result < tsk_id_t , TskitError > {
114- unsafe_tsk_column_access ! ( row, 0 , self . num_rows( ) , self . table_. parent)
113+ pub fn parent < M : Into < MutationId > + Copy > ( & ' a self , row : M ) -> Result < MutationId , TskitError > {
114+ unsafe_tsk_column_access ! (
115+ row. into( ) . 0 ,
116+ 0 ,
117+ self . num_rows( ) ,
118+ self . table_. parent,
119+ MutationId
120+ )
115121 }
116122
117123 /// Return the ``time`` value from row ``row`` of the table.
@@ -120,8 +126,8 @@ impl<'a> MutationTable<'a> {
120126 ///
121127 /// Will return [``IndexError``](crate::TskitError::IndexError)
122128 /// if ``row`` is out of range.
123- pub fn time ( & ' a self , row : tsk_id_t ) -> Result < f64 , TskitError > {
124- unsafe_tsk_column_access ! ( row, 0 , self . num_rows( ) , self . table_. time)
129+ pub fn time < M : Into < MutationId > + Copy > ( & ' a self , row : M ) -> Result < f64 , TskitError > {
130+ unsafe_tsk_column_access ! ( row. into ( ) . 0 , 0 , self . num_rows( ) , self . table_. time)
125131 }
126132
127133 /// Get the ``derived_state`` value from row ``row`` of the table.
@@ -134,21 +140,24 @@ impl<'a> MutationTable<'a> {
134140 ///
135141 /// Will return [``IndexError``](crate::TskitError::IndexError)
136142 /// if ``row`` is out of range.
137- pub fn derived_state ( & ' a self , row : tsk_id_t ) -> Result < Option < Vec < u8 > > , TskitError > {
143+ pub fn derived_state < M : Into < MutationId > > (
144+ & ' a self ,
145+ row : M ,
146+ ) -> Result < Option < Vec < u8 > > , TskitError > {
138147 metadata:: char_column_to_vector (
139148 self . table_ . derived_state ,
140149 self . table_ . derived_state_offset ,
141- row,
150+ row. into ( ) . 0 ,
142151 self . table_ . num_rows ,
143152 self . table_ . derived_state_length ,
144153 )
145154 }
146155
147156 pub fn metadata < T : metadata:: MetadataRoundtrip > (
148157 & ' a self ,
149- row : tsk_id_t ,
158+ row : MutationId ,
150159 ) -> Result < Option < T > , TskitError > {
151- let buffer = metadata_to_vector ! ( self , row) ?;
160+ let buffer = metadata_to_vector ! ( self , row. 0 ) ?;
152161 decode_metadata_row ! ( T , buffer)
153162 }
154163
@@ -167,7 +176,7 @@ impl<'a> MutationTable<'a> {
167176 /// # Errors
168177 ///
169178 /// [`TskitError::IndexError`] if `r` is out of range.
170- pub fn row ( & self , r : tsk_id_t ) -> Result < MutationTableRow , TskitError > {
171- table_row_access ! ( r, self , make_mutation_table_row)
179+ pub fn row < M : Into < MutationId > + Copy > ( & self , r : M ) -> Result < MutationTableRow , TskitError > {
180+ table_row_access ! ( r. into ( ) . 0 , self , make_mutation_table_row)
172181 }
173182}
0 commit comments