@@ -20,6 +20,7 @@ use crate::TreeSequenceFlags;
2020use crate :: TskReturnValue ;
2121use crate :: TskitTypeAccess ;
2222use crate :: { tsk_flags_t, tsk_id_t, tsk_size_t, TSK_NULL } ;
23+ use crate :: { IndividualId , NodeId } ;
2324use ll_bindings:: tsk_table_collection_free;
2425
2526/// A table collection.
@@ -165,7 +166,7 @@ impl TableCollection {
165166 }
166167
167168 /// Add a row to the edge table
168- pub fn add_edge < P : Into < crate :: NodeId > , C : Into < crate :: NodeId > > (
169+ pub fn add_edge < P : Into < NodeId > , C : Into < NodeId > > (
169170 & mut self ,
170171 left : f64 ,
171172 right : f64 ,
@@ -176,7 +177,7 @@ impl TableCollection {
176177 }
177178
178179 /// Add a row with metadata to the edge table
179- pub fn add_edge_with_metadata < P : Into < crate :: NodeId > , C : Into < crate :: NodeId > > (
180+ pub fn add_edge_with_metadata < P : Into < NodeId > , C : Into < NodeId > > (
180181 & mut self ,
181182 left : f64 ,
182183 right : f64 ,
@@ -201,23 +202,23 @@ impl TableCollection {
201202 }
202203
203204 /// Add a row to the individual table
204- pub fn add_individual < N : Into < crate :: NodeId > > (
205+ pub fn add_individual < N : Into < NodeId > > (
205206 & mut self ,
206207 flags : tsk_flags_t ,
207208 location : & [ f64 ] ,
208209 parents : & [ N ] ,
209- ) -> TskReturnValue {
210+ ) -> Result < IndividualId , TskitError > {
210211 self . add_individual_with_metadata ( flags, location, parents, None )
211212 }
212213
213214 /// Add a row with metadata to the individual table
214- pub fn add_individual_with_metadata < N : Into < crate :: NodeId > > (
215+ pub fn add_individual_with_metadata < N : Into < NodeId > > (
215216 & mut self ,
216217 flags : tsk_flags_t ,
217218 location : & [ f64 ] ,
218219 parents : & [ N ] ,
219220 metadata : Option < & dyn MetadataRoundtrip > ,
220- ) -> TskReturnValue {
221+ ) -> Result < IndividualId , TskitError > {
221222 let md = EncodedMetadata :: new ( metadata) ?;
222223 let rv = unsafe {
223224 ll_bindings:: tsk_individual_table_add_row (
@@ -231,7 +232,7 @@ impl TableCollection {
231232 md. len ( ) ,
232233 )
233234 } ;
234- handle_tsk_return_value ! ( rv)
235+ handle_tsk_return_value ! ( rv, IndividualId :: from ( rv ) )
235236 }
236237
237238 /// Add a row to the migration table
@@ -240,7 +241,7 @@ impl TableCollection {
240241 ///
241242 /// Migration tables are not currently supported
242243 /// by tree sequence simplification.
243- pub fn add_migration < N : Into < crate :: NodeId > > (
244+ pub fn add_migration < N : Into < NodeId > > (
244245 & mut self ,
245246 span : ( f64 , f64 ) ,
246247 node : N ,
@@ -256,7 +257,7 @@ impl TableCollection {
256257 ///
257258 /// Migration tables are not currently supported
258259 /// by tree sequence simplification.
259- pub fn add_migration_with_metadata < N : Into < crate :: NodeId > > (
260+ pub fn add_migration_with_metadata < N : Into < NodeId > > (
260261 & mut self ,
261262 span : ( f64 , f64 ) ,
262263 node : N ,
@@ -282,33 +283,33 @@ impl TableCollection {
282283 }
283284
284285 /// Add a row to the node table
285- pub fn add_node (
286+ pub fn add_node < I : Into < IndividualId > > (
286287 & mut self ,
287288 flags : ll_bindings:: tsk_flags_t ,
288289 time : f64 ,
289290 population : tsk_id_t ,
290- individual : tsk_id_t ,
291- ) -> Result < crate :: NodeId , TskitError > {
291+ individual : I ,
292+ ) -> Result < NodeId , TskitError > {
292293 self . add_node_with_metadata ( flags, time, population, individual, None )
293294 }
294295
295296 /// Add a row with metadata to the node table
296- pub fn add_node_with_metadata (
297+ pub fn add_node_with_metadata < I : Into < IndividualId > > (
297298 & mut self ,
298299 flags : ll_bindings:: tsk_flags_t ,
299300 time : f64 ,
300301 population : tsk_id_t ,
301- individual : tsk_id_t ,
302+ individual : I ,
302303 metadata : Option < & dyn MetadataRoundtrip > ,
303- ) -> Result < crate :: NodeId , TskitError > {
304+ ) -> Result < NodeId , TskitError > {
304305 let md = EncodedMetadata :: new ( metadata) ?;
305306 let rv = unsafe {
306307 ll_bindings:: tsk_node_table_add_row (
307308 & mut ( * self . as_mut_ptr ( ) ) . nodes ,
308309 flags,
309310 time,
310311 population,
311- individual,
312+ individual. into ( ) . 0 ,
312313 md. as_ptr ( ) ,
313314 md. len ( ) ,
314315 )
@@ -347,7 +348,7 @@ impl TableCollection {
347348 }
348349
349350 /// Add a row to the mutation table.
350- pub fn add_mutation < N : Into < crate :: NodeId > > (
351+ pub fn add_mutation < N : Into < NodeId > > (
351352 & mut self ,
352353 site : tsk_id_t ,
353354 node : N ,
@@ -359,7 +360,7 @@ impl TableCollection {
359360 }
360361
361362 /// Add a row with metadata to the mutation table.
362- pub fn add_mutation_with_metadata < N : Into < crate :: NodeId > > (
363+ pub fn add_mutation_with_metadata < N : Into < NodeId > > (
363364 & mut self ,
364365 site : tsk_id_t ,
365366 node : N ,
@@ -558,13 +559,13 @@ impl TableCollection {
558559 /// in length to the input node table. For each input node,
559560 /// this vector either contains the node's new index or [`TSK_NULL`]
560561 /// if the input node is not part of the simplified history.
561- pub fn simplify < N : Into < crate :: NodeId > > (
562+ pub fn simplify < N : Into < NodeId > > (
562563 & mut self ,
563564 samples : & [ N ] ,
564565 options : SimplificationOptions ,
565566 idmap : bool ,
566- ) -> Result < Option < Vec < crate :: NodeId > > , TskitError > {
567- let mut output_node_map: Vec < crate :: NodeId > = vec ! [ ] ;
567+ ) -> Result < Option < Vec < NodeId > > , TskitError > {
568+ let mut output_node_map: Vec < NodeId > = vec ! [ ] ;
568569 if idmap {
569570 output_node_map. resize ( self . nodes ( ) . num_rows ( ) as usize , TSK_NULL . into ( ) ) ;
570571 }
0 commit comments