Skip to content

Commit da384f3

Browse files
committed
abstract out common bits
1 parent d10bb6f commit da384f3

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

src/sys.rs

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ pub fn tsk_column_access<
3131
tsk_column_access_detail(row, column, column_length).map(|v| v.into())
3232
}
3333

34-
pub fn tsk_ragged_column_access<
35-
'a,
36-
O,
34+
pub fn tsk_ragged_column_access_detail<
3735
R: Into<bindings::tsk_id_t>,
3836
L: Into<bindings::tsk_size_t>,
3937
T: Copy,
@@ -43,7 +41,7 @@ pub fn tsk_ragged_column_access<
4341
column_length: L,
4442
offset: *const bindings::tsk_size_t,
4543
offset_length: bindings::tsk_size_t,
46-
) -> Option<&'a [O]> {
44+
) -> Option<(*const T, usize)> {
4745
let row = row.into();
4846
let column_length = column_length.into();
4947
if row < 0 || row as bindings::tsk_size_t > column_length || offset_length == 0 {
@@ -61,12 +59,29 @@ pub fn tsk_ragged_column_access<
6159
if start == stop {
6260
None
6361
} else {
64-
Some(unsafe {
65-
std::slice::from_raw_parts(
66-
column.offset(start as isize).cast::<O>(),
67-
stop as usize - start as usize,
68-
)
69-
})
62+
Some((
63+
unsafe { column.offset(start as isize) },
64+
stop as usize - start as usize,
65+
))
7066
}
7167
}
7268
}
69+
70+
pub fn tsk_ragged_column_access<
71+
'a,
72+
O,
73+
R: Into<bindings::tsk_id_t>,
74+
L: Into<bindings::tsk_size_t>,
75+
T: Copy,
76+
>(
77+
row: R,
78+
column: *const T,
79+
column_length: L,
80+
offset: *const bindings::tsk_size_t,
81+
offset_length: bindings::tsk_size_t,
82+
) -> Option<&'a [O]> {
83+
match tsk_ragged_column_access_detail(row, column, column_length, offset, offset_length) {
84+
Some((p, n)) => Some(unsafe { std::slice::from_raw_parts(p.cast::<O>(), n) }),
85+
None => None,
86+
}
87+
}

0 commit comments

Comments
 (0)