Skip to content

Commit 4ef5ec8

Browse files
committed
provenance, too
1 parent dc42784 commit 4ef5ec8

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/provenance.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,51 @@ impl ProvenanceTable {
262262
make_provenance_row(self, row.into().0)
263263
}
264264

265+
/// Obtain a [`ProvenanceTableRowView`] for row `row`.
266+
///
267+
/// # Returns
268+
///
269+
/// * `Some(row view)` if `r` is valid
270+
/// * `None` otherwise
271+
pub fn row_view<P: Into<ProvenanceId> + Copy>(&self, row: P) -> Option<ProvenanceTableRowView> {
272+
match u64::try_from(row.into().0).ok() {
273+
Some(x) if x < self.num_rows() => {
274+
let record_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8!(
275+
row.into().0,
276+
0,
277+
self.num_rows(),
278+
self.as_ref(),
279+
record,
280+
record_offset,
281+
record_length
282+
);
283+
let timestamp_slice = unsafe_tsk_ragged_char_column_access_to_slice_u8!(
284+
row.into().0,
285+
0,
286+
self.num_rows(),
287+
self.as_ref(),
288+
timestamp,
289+
timestamp_offset,
290+
timestamp_length
291+
);
292+
let view = ProvenanceTableRowView {
293+
table: self,
294+
id: row.into(),
295+
record: match record_slice {
296+
Some(r) => std::str::from_utf8(r).unwrap(),
297+
None => "",
298+
},
299+
timestamp: match timestamp_slice {
300+
Some(t) => std::str::from_utf8(t).unwrap(),
301+
None => "",
302+
},
303+
};
304+
Some(view)
305+
}
306+
_ => None,
307+
}
308+
}
309+
265310
/// Return an iterator over rows of the table.
266311
/// The value of the iterator is [`ProvenanceTableRow`].
267312
pub fn iter(&self) -> impl Iterator<Item = ProvenanceTableRow> + '_ {

0 commit comments

Comments
 (0)