Skip to content

Commit c245585

Browse files
committed
more
1 parent 491c86d commit c245585

File tree

1 file changed

+36
-8
lines changed

1 file changed

+36
-8
lines changed

src/edge_table.rs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,15 @@ 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-
sys::tsk_column_access::<NodeId, _, _, _>(row.into(), self.as_ref().parent, self.num_rows())
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+
}
227235
}
228236

229237
/// Return the ``child`` value from row ``row`` of the table.
@@ -233,7 +241,15 @@ impl EdgeTable {
233241
/// * `Some(child)` if `u` is valid.
234242
/// * `None` otherwise.
235243
pub fn child<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<NodeId> {
236-
sys::tsk_column_access::<NodeId, _, _, _>(row.into(), self.as_ref().child, self.num_rows())
244+
assert!(self.num_rows() == 0 || !self.as_ref().child.is_null());
245+
// SAFETY: either the column is empty or the point is not NULL
246+
unsafe {
247+
sys::tsk_column_access::<NodeId, _, _, _>(
248+
row.into(),
249+
self.as_ref().child,
250+
self.num_rows(),
251+
)
252+
}
237253
}
238254

239255
/// Return the ``left`` value from row ``row`` of the table.
@@ -243,7 +259,15 @@ impl EdgeTable {
243259
/// * `Some(position)` if `u` is valid.
244260
/// * `None` otherwise.
245261
pub fn left<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position> {
246-
sys::tsk_column_access::<Position, _, _, _>(row.into(), self.as_ref().left, self.num_rows())
262+
assert!(self.num_rows() == 0 || !self.as_ref().left.is_null());
263+
// SAFETY: either the column is empty or the point is not NULL
264+
unsafe {
265+
sys::tsk_column_access::<Position, _, _, _>(
266+
row.into(),
267+
self.as_ref().left,
268+
self.num_rows(),
269+
)
270+
}
247271
}
248272

249273
/// Return the ``right`` value from row ``row`` of the table.
@@ -253,11 +277,15 @@ impl EdgeTable {
253277
/// * `Some(position)` if `u` is valid.
254278
/// * `None` otherwise.
255279
pub fn right<E: Into<EdgeId> + Copy>(&self, row: E) -> Option<Position> {
256-
sys::tsk_column_access::<Position, _, _, _>(
257-
row.into(),
258-
self.as_ref().right,
259-
self.num_rows(),
260-
)
280+
assert!(self.num_rows() == 0 || !self.as_ref().right.is_null());
281+
// SAFETY: either the column is empty or the point is not NULL
282+
unsafe {
283+
sys::tsk_column_access::<Position, _, _, _>(
284+
row.into(),
285+
self.as_ref().right,
286+
self.num_rows(),
287+
)
288+
}
261289
}
262290

263291
/// Retrieve decoded metadata for a `row`.

0 commit comments

Comments
 (0)