Skip to content

Commit cfd22ac

Browse files
committed
set_prov
1 parent 80f51bb commit cfd22ac

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/table_collection.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,45 @@ impl TableCollection {
11131113
};
11141114
handle_tsk_return_value!(rv)
11151115
}
1116+
1117+
#[cfg(any(doc, feature = "provenance"))]
1118+
/// Set the provenance table from an [`OwnedProvenanceTable`](`crate::provenance::OwnedSiteTable`)
1119+
///
1120+
/// # Errors
1121+
///
1122+
/// Any errors from the C API propagate.
1123+
///
1124+
/// # Example
1125+
///
1126+
/// ```rust
1127+
/// # #[cfg(feature="provenance")] {
1128+
/// # use tskit::TableAccess;
1129+
/// let mut tables = tskit::TableCollection::new(1.0).unwrap();
1130+
/// let mut provenances = tskit::OwnedProvenanceTable::default();
1131+
/// provenances.add_row("I like pancakes").unwrap();
1132+
/// tables.set_provenances(&provenances).unwrap();
1133+
/// assert_eq!(tables.provenances().num_rows(), 1);
1134+
/// assert_eq!(tables.provenances().record(0), "I like pancakes");
1135+
/// # provenances.clear().unwrap();
1136+
/// # assert_eq!(provenances.num_rows(), 0);
1137+
/// # }
1138+
/// ```
1139+
pub fn set_provenances(
1140+
&mut self,
1141+
provenances: &crate::provenance::OwnedProvenanceTable,
1142+
) -> TskReturnValue {
1143+
let rv = unsafe {
1144+
ll_bindings::tsk_provenance_table_set_columns(
1145+
&mut (*self.inner).provenances,
1146+
(*provenances.as_ptr()).num_rows,
1147+
(*provenances.as_ptr()).timestamp,
1148+
(*provenances.as_ptr()).timestamp_offset,
1149+
(*provenances.as_ptr()).record,
1150+
(*provenances.as_ptr()).record_offset,
1151+
)
1152+
};
1153+
handle_tsk_return_value!(rv)
1154+
}
11161155
}
11171156

11181157
impl TableAccess for TableCollection {

0 commit comments

Comments
 (0)