File tree Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Expand file tree Collapse file tree 3 files changed +13
-6
lines changed Original file line number Diff line number Diff line change @@ -368,9 +368,9 @@ fn simplify(
368
368
Ok ( x) => match x {
369
369
Some ( idmap) => {
370
370
for a in alive. iter_mut ( ) {
371
- a. node0 = idmap[ usize:: from ( a. node0 ) ] ;
371
+ a. node0 = idmap[ usize:: try_from ( a. node0 ) . unwrap ( ) ] ;
372
372
assert ! ( a. node0 != tskit:: NodeId :: NULL ) ;
373
- a. node1 = idmap[ usize:: from ( a. node1 ) ] ;
373
+ a. node1 = idmap[ usize:: try_from ( a. node1 ) . unwrap ( ) ] ;
374
374
assert ! ( a. node1 != tskit:: NodeId :: NULL ) ;
375
375
}
376
376
}
Original file line number Diff line number Diff line change @@ -248,9 +248,16 @@ macro_rules! impl_id_traits {
248
248
}
249
249
}
250
250
251
- impl From <$idtype> for usize {
252
- fn from( value: $idtype) -> Self {
253
- value. 0 as usize
251
+ impl TryFrom <$idtype> for usize {
252
+ type Error = crate :: TskitError ;
253
+ fn try_from( value: $idtype) -> Result <Self , Self :: Error > {
254
+ match value. 0 . try_into( ) {
255
+ Ok ( value) => Ok ( value) ,
256
+ Err ( _) => Err ( crate :: TskitError :: RangeError ( format!(
257
+ "could not convert {:?} to usize" ,
258
+ value
259
+ ) ) ) ,
260
+ }
254
261
}
255
262
}
256
263
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ mod tests {
37
37
assert ! ( idmap_option. is_some( ) ) ;
38
38
let idmap = idmap_option. unwrap ( ) ;
39
39
for & i in samples {
40
- assert_ne ! ( idmap[ usize :: from ( i ) ] , NodeId :: NULL ) ;
40
+ assert_ne ! ( idmap[ usize :: try_from ( i ) . unwrap ( ) ] , NodeId :: NULL ) ;
41
41
}
42
42
}
43
43
}
You can’t perform that action at this time.
0 commit comments