@@ -46,13 +46,15 @@ macro_rules! unsafe_tsk_column_access {
4646
4747macro_rules! unsafe_tsk_ragged_column_access {
4848 ( $i: expr, $lo: expr, $hi: expr, $array: expr, $offset_array: expr, $offset_array_len: expr) => { {
49- if $i < $lo || $i >= ( $hi as tsk_id_t) {
49+ use std:: convert:: TryFrom ;
50+ let i = crate :: SizeType :: try_from( $i) ?;
51+ if $i < $lo || i >= $hi {
5052 Err ( TskitError :: IndexError { } )
5153 } else if $offset_array_len == 0 {
5254 Ok ( None )
5355 } else {
5456 let start = unsafe { * $offset_array. offset( $i as isize ) } ;
55- let stop = if $ i < ( $hi as tsk_id_t ) {
57+ let stop = if i < $hi {
5658 unsafe { * $offset_array. offset( ( $i + 1 ) as isize ) }
5759 } else {
5860 $offset_array_len as tsk_size_t
@@ -70,13 +72,15 @@ macro_rules! unsafe_tsk_ragged_column_access {
7072 } } ;
7173
7274 ( $i: expr, $lo: expr, $hi: expr, $array: expr, $offset_array: expr, $offset_array_len: expr, $output_id_type: expr) => { {
73- if $i < $lo || $i >= ( $hi as tsk_id_t) {
75+ use std:: convert:: TryFrom ;
76+ let i = crate :: SizeType :: try_from( $i) ?;
77+ if $i < $lo || i >= $hi {
7478 Err ( TskitError :: IndexError { } )
7579 } else if $offset_array_len == 0 {
7680 Ok ( None )
7781 } else {
7882 let start = unsafe { * $offset_array. offset( $i as isize ) } ;
79- let stop = if $ i < ( $hi as tsk_id_t ) {
83+ let stop = if i < $hi {
8084 unsafe { * $offset_array. offset( ( $i + 1 ) as isize ) }
8185 } else {
8286 $offset_array_len as tsk_size_t
@@ -99,13 +103,15 @@ macro_rules! unsafe_tsk_ragged_column_access {
99103#[ allow( unused_macros) ]
100104macro_rules! unsafe_tsk_ragged_char_column_access {
101105 ( $i: expr, $lo: expr, $hi: expr, $array: expr, $offset_array: expr, $offset_array_len: expr) => { {
102- if $i < $lo || $i >= ( $hi as tsk_id_t) {
106+ use std:: convert:: TryFrom ;
107+ let i = crate :: SizeType :: try_from( $i) ?;
108+ if $i < $lo || i >= $hi {
103109 Err ( TskitError :: IndexError { } )
104110 } else if $offset_array_len == 0 {
105111 Ok ( None )
106112 } else {
107113 let start = unsafe { * $offset_array. offset( $i as isize ) } ;
108- let stop = if $ i < ( $hi as tsk_id_t ) {
114+ let stop = if i < $hi {
109115 unsafe { * $offset_array. offset( ( $i + 1 ) as isize ) }
110116 } else {
111117 $offset_array_len as tsk_size_t
@@ -299,6 +305,14 @@ macro_rules! impl_id_traits {
299305 }
300306 }
301307
308+ impl std:: convert:: TryFrom <$idtype> for crate :: SizeType {
309+ type Error = crate :: TskitError ;
310+
311+ fn try_from( value: $idtype) -> Result <Self , Self :: Error > {
312+ crate :: SizeType :: try_from( value. 0 )
313+ }
314+ }
315+
302316 impl PartialEq <$crate:: tsk_id_t> for $idtype {
303317 fn eq( & self , other: & $crate:: tsk_id_t) -> bool {
304318 self . 0 == * other
@@ -325,6 +339,35 @@ macro_rules! impl_id_traits {
325339 } ;
326340}
327341
342+ macro_rules! impl_size_type_comparisons_for_row_ids {
343+ ( $idtype: ty) => {
344+ impl PartialEq <$idtype> for crate :: SizeType {
345+ fn eq( & self , other: & $idtype) -> bool {
346+ self . 0 == other. 0 as crate :: bindings:: tsk_size_t
347+ }
348+ }
349+
350+ impl PartialEq <crate :: SizeType > for $idtype {
351+ fn eq( & self , other: & crate :: SizeType ) -> bool {
352+ ( self . 0 as crate :: bindings:: tsk_size_t) == other. 0
353+ }
354+ }
355+
356+ impl PartialOrd <$idtype> for crate :: SizeType {
357+ fn partial_cmp( & self , other: & $idtype) -> Option <std:: cmp:: Ordering > {
358+ self . 0
359+ . partial_cmp( & ( other. 0 as crate :: bindings:: tsk_size_t) )
360+ }
361+ }
362+
363+ impl PartialOrd <crate :: SizeType > for $idtype {
364+ fn partial_cmp( & self , other: & crate :: SizeType ) -> Option <std:: cmp:: Ordering > {
365+ ( self . 0 as crate :: bindings:: tsk_size_t) . partial_cmp( & other. 0 )
366+ }
367+ }
368+ } ;
369+ }
370+
328371/// Convenience macro to handle implementing
329372/// [`crate::metadata::MetadataRoundtrip`]
330373#[ macro_export]
0 commit comments