File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -987,6 +987,26 @@ macro_rules! migration_table_add_row_with_metadata {
987
987
}
988
988
} ;
989
989
}
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
+
990
1010
#[ cfg( test) ]
991
1011
mod test {
992
1012
use crate :: error:: TskitError ;
Original file line number Diff line number Diff line change @@ -808,6 +808,7 @@ impl TableCollection {
808
808
}
809
809
810
810
#[ cfg( any( feature = "provenance" , doc) ) ]
811
+ provenance_table_add_row ! (
811
812
/// Add provenance record with a time stamp.
812
813
///
813
814
/// All implementation of this trait provided by `tskit` use
@@ -856,19 +857,7 @@ impl TableCollection {
856
857
/// assert_eq!(treeseq.provenances().record(0).unwrap(), row_0.record);
857
858
/// # }
858
859
/// ```
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) ;
872
861
}
873
862
874
863
impl TableAccess for TableCollection {
You can’t perform that action at this time.
0 commit comments