@@ -295,18 +295,18 @@ impl TreeInterface {
295295
296296 // error if we are not tracking samples,
297297 // Ok(None) if u is out of range
298- fn left_sample ( & self , u : NodeId ) -> Option < NodeId > {
298+ fn left_sample < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
299299 // SAFETY: internal pointer cannot be NULL
300300 let ptr = unsafe { * self . as_ptr ( ) } ;
301- unsafe_tsk_column_access ! ( u. 0 , 0 , self . num_nodes, ptr, left_sample, NodeId )
301+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . num_nodes, ptr, left_sample, NodeId )
302302 }
303303
304304 // error if we are not tracking samples,
305305 // Ok(None) if u is out of range
306- fn right_sample ( & self , u : NodeId ) -> Option < NodeId > {
306+ fn right_sample < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
307307 // SAFETY: internal pointer cannot be NULL
308308 let ptr = unsafe { * self . as_ptr ( ) } ;
309- unsafe_tsk_column_access ! ( u. 0 , 0 , self . num_nodes, ptr, right_sample, NodeId )
309+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . num_nodes, ptr, right_sample, NodeId )
310310 }
311311
312312 /// Return the `[left, right)` coordinates of the tree.
@@ -328,46 +328,46 @@ impl TreeInterface {
328328 /// Get the parent of node `u`.
329329 ///
330330 /// Returns `None` if `u` is out of range.
331- pub fn parent ( & self , u : NodeId ) -> Option < NodeId > {
331+ pub fn parent < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
332332 // SAFETY: internal pointer cannot be NULL
333333 let ptr = unsafe { * self . as_ptr ( ) } ;
334- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, parent, NodeId )
334+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, parent, NodeId )
335335 }
336336
337337 /// Get the left child of node `u`.
338338 ///
339339 /// Returns `None` if `u` is out of range.
340- pub fn left_child ( & self , u : NodeId ) -> Option < NodeId > {
340+ pub fn left_child < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
341341 // SAFETY: internal pointer cannot be NULL
342342 let ptr = unsafe { * self . as_ptr ( ) } ;
343- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, left_child, NodeId )
343+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, left_child, NodeId )
344344 }
345345
346346 /// Get the right child of node `u`.
347347 ///
348348 /// Returns `None` if `u` is out of range.
349- pub fn right_child ( & self , u : NodeId ) -> Option < NodeId > {
349+ pub fn right_child < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
350350 // SAFETY: internal pointer cannot be NULL
351351 let ptr = unsafe { * self . as_ptr ( ) } ;
352- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, right_child, NodeId )
352+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, right_child, NodeId )
353353 }
354354
355355 /// Get the left sib of node `u`.
356356 ///
357357 /// Returns `None` if `u` is out of range.
358- pub fn left_sib ( & self , u : NodeId ) -> Option < NodeId > {
358+ pub fn left_sib < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
359359 // SAFETY: internal pointer cannot be NULL
360360 let ptr = unsafe { * self . as_ptr ( ) } ;
361- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, left_sib, NodeId )
361+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, left_sib, NodeId )
362362 }
363363
364364 /// Get the right sib of node `u`.
365365 ///
366366 /// Returns `None` if `u` is out of range.
367- pub fn right_sib ( & self , u : NodeId ) -> Option < NodeId > {
367+ pub fn right_sib < N : Into < NodeId > + Copy > ( & self , u : N ) -> Option < NodeId > {
368368 // SAFETY: internal pointer cannot be NULL
369369 let ptr = unsafe { * self . as_ptr ( ) } ;
370- unsafe_tsk_column_access ! ( u. 0 , 0 , self . array_len, ptr, right_sib, NodeId )
370+ unsafe_tsk_column_access ! ( u. into ( ) . 0 , 0 , self . array_len, ptr, right_sib, NodeId )
371371 }
372372
373373 /// Obtain the list of samples for the current tree/tree sequence
@@ -406,17 +406,17 @@ impl TreeInterface {
406406 ///
407407 /// * `Some(iterator)` if `u` is valid
408408 /// * `None` otherwise
409- pub fn parents ( & self , u : NodeId ) -> impl Iterator < Item = NodeId > + ' _ {
410- ParentsIterator :: new ( self , u)
409+ pub fn parents < N : Into < NodeId > + Copy > ( & self , u : N ) -> impl Iterator < Item = NodeId > + ' _ {
410+ ParentsIterator :: new ( self , u. into ( ) )
411411 }
412412
413413 /// Return an [`Iterator`] over the children of node `u`.
414414 /// # Returns
415415 ///
416416 /// * `Some(iterator)` if `u` is valid
417417 /// * `None` otherwise
418- pub fn children ( & self , u : NodeId ) -> impl Iterator < Item = NodeId > + ' _ {
419- ChildIterator :: new ( self , u)
418+ pub fn children < N : Into < NodeId > + Copy > ( & self , u : N ) -> impl Iterator < Item = NodeId > + ' _ {
419+ ChildIterator :: new ( self , u. into ( ) )
420420 }
421421
422422 /// Return an [`Iterator`] over the sample nodes descending from node `u`.
@@ -430,8 +430,11 @@ impl TreeInterface {
430430 /// * Some(Ok(iterator)) if [`TreeFlags::SAMPLE_LISTS`] is in [`TreeInterface::flags`]
431431 /// * Some(Err(_)) if [`TreeFlags::SAMPLE_LISTS`] is not in [`TreeInterface::flags`]
432432 /// * None if `u` is not valid.
433- pub fn samples ( & self , u : NodeId ) -> Result < impl Iterator < Item = NodeId > + ' _ , TskitError > {
434- SamplesIterator :: new ( self , u)
433+ pub fn samples < N : Into < NodeId > + Copy > (
434+ & self ,
435+ u : N ,
436+ ) -> Result < impl Iterator < Item = NodeId > + ' _ , TskitError > {
437+ SamplesIterator :: new ( self , u. into ( ) )
435438 }
436439
437440 /// Return an [`Iterator`] over the roots of the tree.
@@ -514,10 +517,14 @@ impl TreeInterface {
514517 /// # Errors
515518 ///
516519 /// * [`TskitError`] if [`TreeFlags::NO_SAMPLE_COUNTS`].
517- pub fn num_tracked_samples ( & self , u : NodeId ) -> Result < SizeType , TskitError > {
520+ pub fn num_tracked_samples < N : Into < NodeId > + Copy > (
521+ & self ,
522+ u : N ,
523+ ) -> Result < SizeType , TskitError > {
518524 let mut n = SizeType ( tsk_size_t:: MAX ) ;
519525 let np: * mut tsk_size_t = & mut n. 0 ;
520- let code = unsafe { ll_bindings:: tsk_tree_get_num_tracked_samples ( self . as_ptr ( ) , u. 0 , np) } ;
526+ let code =
527+ unsafe { ll_bindings:: tsk_tree_get_num_tracked_samples ( self . as_ptr ( ) , u. into ( ) . 0 , np) } ;
521528 handle_tsk_return_value ! ( code, n)
522529 }
523530
0 commit comments