Skip to content

Commit 4647571

Browse files
committed
provenance
1 parent 2fd98a6 commit 4647571

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/_macros.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,26 @@ macro_rules! migration_table_add_row_with_metadata {
987987
}
988988
};
989989
}
990+
991+
macro_rules! provenance_table_add_row {
992+
($(#[$attr:meta])* => $name: ident, $self: ident, $table: expr) => {
993+
$(#[$attr])*
994+
pub fn $name(&mut $self, record: &str) -> Result<$crate::ProvenanceId, $crate::TskitError> {
995+
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
996+
let rv = unsafe {
997+
$crate::bindings::tsk_provenance_table_add_row(
998+
&mut $table,
999+
timestamp.as_ptr() as *mut i8,
1000+
timestamp.len() as tsk_size_t,
1001+
record.as_ptr() as *mut i8,
1002+
record.len() as tsk_size_t,
1003+
)
1004+
};
1005+
handle_tsk_return_value!(rv, rv.into())
1006+
}
1007+
};
1008+
}
1009+
9901010
#[cfg(test)]
9911011
mod test {
9921012
use crate::error::TskitError;

src/table_collection.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ impl TableCollection {
808808
}
809809

810810
#[cfg(any(feature = "provenance", doc))]
811+
provenance_table_add_row!(
811812
/// Add provenance record with a time stamp.
812813
///
813814
/// All implementation of this trait provided by `tskit` use
@@ -856,19 +857,7 @@ impl TableCollection {
856857
/// assert_eq!(treeseq.provenances().record(0).unwrap(), row_0.record);
857858
/// # }
858859
/// ```
859-
pub fn add_provenance(&mut self, record: &str) -> Result<crate::ProvenanceId, TskitError> {
860-
let timestamp = humantime::format_rfc3339(std::time::SystemTime::now()).to_string();
861-
let rv = unsafe {
862-
ll_bindings::tsk_provenance_table_add_row(
863-
&mut (*self.inner).provenances,
864-
timestamp.as_ptr() as *mut i8,
865-
timestamp.len() as tsk_size_t,
866-
record.as_ptr() as *mut i8,
867-
record.len() as tsk_size_t,
868-
)
869-
};
870-
handle_tsk_return_value!(rv, crate::ProvenanceId::from(rv))
871-
}
860+
=> add_provenance, self, (*self.inner).provenances);
872861
}
873862

874863
impl TableAccess for TableCollection {

0 commit comments

Comments
 (0)