Skip to content

Commit

Permalink
strong id type cleanup (#139)
Browse files Browse the repository at this point in the history
* Fix missing use of IndividualId in NodeTable/NodeTableRow

* *::metadata table functions require row ID types.
  • Loading branch information
molpopgen authored Jul 21, 2021
1 parent 6bae100 commit 1203a5d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/individual_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ impl<'a> IndividualTable<'a> {
/// # Errors
///
/// * [`TskitError::IndexError`] if `row` is out of range.
pub fn metadata<I: Into<IndividualId>, T: metadata::MetadataRoundtrip>(
pub fn metadata<T: metadata::MetadataRoundtrip>(
&'a self,
row: I,
row: IndividualId,
) -> Result<Option<T>, TskitError> {
let buffer = metadata_to_vector!(self, row.into().0)?;
let buffer = metadata_to_vector!(self, row.0)?;
decode_metadata_row!(T, buffer)
}

Expand Down
23 changes: 16 additions & 7 deletions src/node_table.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::bindings as ll_bindings;
use crate::metadata;
use crate::{tsk_flags_t, tsk_id_t, TskitError};
use crate::{NodeId, PopulationId};
use crate::{IndividualId, NodeId, PopulationId};

/// Row of a [`NodeTable`]
pub struct NodeTableRow {
pub id: NodeId,
pub time: f64,
pub flags: tsk_flags_t,
pub population: PopulationId,
pub individual: tsk_id_t,
pub individual: IndividualId,
pub metadata: Option<Vec<u8>>,
}

Expand Down Expand Up @@ -146,15 +146,24 @@ impl<'a> NodeTable<'a> {
///
/// Will return [``IndexError``](crate::TskitError::IndexError)
/// if ``row`` is out of range.
pub fn individual<N: Into<NodeId> + Copy>(&'a self, row: N) -> Result<tsk_id_t, TskitError> {
unsafe_tsk_column_access!(row.into().0, 0, self.num_rows(), self.table_.individual)
pub fn individual<N: Into<NodeId> + Copy>(
&'a self,
row: N,
) -> Result<IndividualId, TskitError> {
unsafe_tsk_column_access!(
row.into().0,
0,
self.num_rows(),
self.table_.individual,
IndividualId
)
}

pub fn metadata<N: Into<crate::NodeId>, T: metadata::MetadataRoundtrip>(
pub fn metadata<T: metadata::MetadataRoundtrip>(
&'a self,
row: N,
row: NodeId,
) -> Result<Option<T>, TskitError> {
let buffer = metadata_to_vector!(self, row.into().0)?;
let buffer = metadata_to_vector!(self, row.0)?;
decode_metadata_row!(T, buffer)
}

Expand Down
6 changes: 3 additions & 3 deletions src/population_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ impl<'a> PopulationTable<'a> {
self.table_.num_rows
}

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

Expand Down

0 comments on commit 1203a5d

Please sign in to comment.