Skip to content

Commit b37a59a

Browse files
committed
sites, pt 2
1 parent faa0abf commit b37a59a

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

src/_macros.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,23 @@ macro_rules! site_table_add_row {
914914
};
915915
}
916916

917+
macro_rules! site_table_add_row_with_metadata {
918+
($(#[$attr:meta])* => $name: ident, $self: ident, $table: expr) => {
919+
$(#[$attr])*
920+
pub fn $name<M>(&mut $self,
921+
position: impl Into<$crate::Position>,
922+
ancestral_state: Option<&[u8]>,
923+
metadata: &M) -> Result<$crate::SiteId, $crate::TskitError>
924+
where M: $crate::metadata::SiteMetadata {
925+
let md = $crate::metadata::EncodedMetadata::new(metadata)?;
926+
site_table_add_row_details!(position, ancestral_state,
927+
md.as_ptr(),
928+
md.len().into(),
929+
$table)
930+
}
931+
};
932+
}
933+
917934
#[cfg(test)]
918935
mod test {
919936
use crate::error::TskitError;

src/table_collection.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::TreeSequenceFlags;
2424
use crate::TskReturnValue;
2525
use crate::TskitTypeAccess;
2626
use crate::{tsk_id_t, tsk_size_t};
27-
use crate::{EdgeId, MigrationId, NodeId, PopulationId, SiteId};
27+
use crate::{EdgeId, MigrationId, NodeId, PopulationId};
2828
use ll_bindings::tsk_table_collection_free;
2929
use mbox::MBox;
3030

@@ -454,6 +454,7 @@ impl TableCollection {
454454
/// Add a row to the site table
455455
=> add_site, self, (*self.inner).sites);
456456

457+
site_table_add_row_with_metadata!(
457458
/// Add a row with optional metadata to the site table
458459
///
459460
/// # Examples
@@ -476,28 +477,7 @@ impl TableCollection {
476477
/// &metadata).is_ok());
477478
/// # }
478479
/// ```
479-
pub fn add_site_with_metadata<P: Into<Position>, M: SiteMetadata>(
480-
&mut self,
481-
position: P,
482-
ancestral_state: Option<&[u8]>,
483-
metadata: &M,
484-
) -> Result<SiteId, TskitError> {
485-
let astate = process_state_input!(ancestral_state);
486-
let md = EncodedMetadata::new(metadata)?;
487-
488-
let rv = unsafe {
489-
ll_bindings::tsk_site_table_add_row(
490-
&mut (*self.as_mut_ptr()).sites,
491-
position.into().0,
492-
astate.0,
493-
astate.1,
494-
md.as_ptr(),
495-
md.len().into(),
496-
)
497-
};
498-
499-
handle_tsk_return_value!(rv, SiteId::from(rv))
500-
}
480+
=> add_site_with_metadata, self, (*self.inner).sites);
501481

502482
mutation_table_add_row!(
503483
/// Add a row to the mutation table.

0 commit comments

Comments
 (0)