Skip to content

Commit 1203a5d

Browse files
authored
strong id type cleanup (#139)
* Fix missing use of IndividualId in NodeTable/NodeTableRow * *::metadata table functions require row ID types.
1 parent 6bae100 commit 1203a5d

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

src/individual_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,11 @@ impl<'a> IndividualTable<'a> {
132132
/// # Errors
133133
///
134134
/// * [`TskitError::IndexError`] if `row` is out of range.
135-
pub fn metadata<I: Into<IndividualId>, T: metadata::MetadataRoundtrip>(
135+
pub fn metadata<T: metadata::MetadataRoundtrip>(
136136
&'a self,
137-
row: I,
137+
row: IndividualId,
138138
) -> Result<Option<T>, TskitError> {
139-
let buffer = metadata_to_vector!(self, row.into().0)?;
139+
let buffer = metadata_to_vector!(self, row.0)?;
140140
decode_metadata_row!(T, buffer)
141141
}
142142

src/node_table.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::bindings as ll_bindings;
22
use crate::metadata;
33
use crate::{tsk_flags_t, tsk_id_t, TskitError};
4-
use crate::{NodeId, PopulationId};
4+
use crate::{IndividualId, NodeId, PopulationId};
55

66
/// Row of a [`NodeTable`]
77
pub struct NodeTableRow {
88
pub id: NodeId,
99
pub time: f64,
1010
pub flags: tsk_flags_t,
1111
pub population: PopulationId,
12-
pub individual: tsk_id_t,
12+
pub individual: IndividualId,
1313
pub metadata: Option<Vec<u8>>,
1414
}
1515

@@ -146,15 +146,24 @@ impl<'a> NodeTable<'a> {
146146
///
147147
/// Will return [``IndexError``](crate::TskitError::IndexError)
148148
/// if ``row`` is out of range.
149-
pub fn individual<N: Into<NodeId> + Copy>(&'a self, row: N) -> Result<tsk_id_t, TskitError> {
150-
unsafe_tsk_column_access!(row.into().0, 0, self.num_rows(), self.table_.individual)
149+
pub fn individual<N: Into<NodeId> + Copy>(
150+
&'a self,
151+
row: N,
152+
) -> Result<IndividualId, TskitError> {
153+
unsafe_tsk_column_access!(
154+
row.into().0,
155+
0,
156+
self.num_rows(),
157+
self.table_.individual,
158+
IndividualId
159+
)
151160
}
152161

153-
pub fn metadata<N: Into<crate::NodeId>, T: metadata::MetadataRoundtrip>(
162+
pub fn metadata<T: metadata::MetadataRoundtrip>(
154163
&'a self,
155-
row: N,
164+
row: NodeId,
156165
) -> Result<Option<T>, TskitError> {
157-
let buffer = metadata_to_vector!(self, row.into().0)?;
166+
let buffer = metadata_to_vector!(self, row.0)?;
158167
decode_metadata_row!(T, buffer)
159168
}
160169

src/population_table.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ impl<'a> PopulationTable<'a> {
7272
self.table_.num_rows
7373
}
7474

75-
pub fn metadata<P: Into<PopulationId>, T: metadata::MetadataRoundtrip>(
75+
pub fn metadata<T: metadata::MetadataRoundtrip>(
7676
&'a self,
77-
row: P,
77+
row: PopulationId,
7878
) -> Result<Option<T>, TskitError> {
79-
let buffer = metadata_to_vector!(self, row.into().0)?;
79+
let buffer = metadata_to_vector!(self, row.0)?;
8080
decode_metadata_row!(T, buffer)
8181
}
8282

0 commit comments

Comments
 (0)