Skip to content

Commit 489509a

Browse files
committed
cool
1 parent 334ed5e commit 489509a

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/edge_table.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,7 @@ impl EdgeTable {
223223
/// * `Some(parent)` if `u` is valid.
224224
/// * `None` otherwise.
225225
pub fn parent<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId> {
226-
assert!(self.num_rows() == 0 || !self.as_ref().parent.is_null());
227-
// SAFETY: either the column is empty or the point is not NULL
228-
unsafe {
229-
sys::tsk_column_access::<NodeId, _, _, _>(
230-
row.into(),
231-
self.as_ref().parent,
232-
self.num_rows(),
233-
)
234-
}
226+
self.table_.parent(row.into())
235227
}
236228

237229
/// Return the ``child`` value from row ``row`` of the table.

src/sys/edge_table.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::ptr::NonNull;
22

3+
use super::newtypes::EdgeId;
4+
use super::newtypes::NodeId;
5+
36
use super::bindings::tsk_edge_table_add_row;
47
use super::bindings::tsk_edge_table_clear;
58
use super::bindings::tsk_edge_table_init;
@@ -65,6 +68,10 @@ impl EdgeTable {
6568
))
6669
}
6770
}
71+
72+
pub fn parent(&self, row: EdgeId) -> Option<NodeId> {
73+
safe_tsk_column_access!(self, row, NodeId, parent)
74+
}
6875
}
6976

7077
impl Default for EdgeTable {

src/sys/macros.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,18 @@ macro_rules! impl_time_position_arithmetic {
277277
}
278278
};
279279
}
280+
281+
macro_rules! safe_tsk_column_access {
282+
($self: ident, $u: ident, $output_type: ty, $column: ident) => {{
283+
assert!($self.as_ref().num_rows == 0 || !$self.as_ref().$column.is_null());
284+
// SAFETY: row is empty or is that the column is not a null pointer
285+
// and the length is from the C API
286+
unsafe {
287+
super::tsk_column_access::<$output_type, _, _, _>(
288+
$u,
289+
$self.as_ref().$column,
290+
$self.as_ref().num_rows,
291+
)
292+
}
293+
}};
294+
}

0 commit comments

Comments
 (0)