@@ -32,6 +32,12 @@ impl TreeInterface {
32
32
}
33
33
}
34
34
35
+ fn as_ref ( & self ) -> & ll_bindings:: tsk_tree_t {
36
+ // SAFETY: we have already successfuly constructed
37
+ // the NonNull
38
+ unsafe { self . non_owned_pointer . as_ref ( ) }
39
+ }
40
+
35
41
/// Pointer to the low-level C type.
36
42
pub fn as_ptr ( & self ) -> * const ll_bindings:: tsk_tree_t {
37
43
self . non_owned_pointer . as_ptr ( )
@@ -63,7 +69,7 @@ impl TreeInterface {
63
69
/// }
64
70
/// ```
65
71
pub fn parent_array ( & self ) -> & [ NodeId ] {
66
- tree_array_slice ! ( self , parent, self . array_len)
72
+ sys :: tree_array_slice ( self . as_ref ( ) . parent , self . array_len )
67
73
}
68
74
69
75
/// # Failing examples
@@ -99,7 +105,10 @@ impl TreeInterface {
99
105
pub fn samples_array ( & self ) -> Result < & [ NodeId ] , TskitError > {
100
106
let num_samples =
101
107
unsafe { ll_bindings:: tsk_treeseq_get_num_samples ( ( * self . as_ptr ( ) ) . tree_sequence ) } ;
102
- err_if_not_tracking_samples ! ( self . flags, tree_array_slice!( self , samples, num_samples) )
108
+ err_if_not_tracking_samples ! (
109
+ self . flags,
110
+ sys:: tree_array_slice( self . as_ref( ) . samples, num_samples)
111
+ )
103
112
}
104
113
105
114
/// # Failing examples
@@ -135,7 +144,7 @@ impl TreeInterface {
135
144
pub fn next_sample_array ( & self ) -> Result < & [ NodeId ] , TskitError > {
136
145
err_if_not_tracking_samples ! (
137
146
self . flags,
138
- tree_array_slice! ( self , next_sample, ( * self . as_ptr ( ) ) . num_nodes )
147
+ sys :: tree_array_slice( self . as_ref ( ) . next_sample, self . array_len )
139
148
)
140
149
}
141
150
@@ -172,7 +181,7 @@ impl TreeInterface {
172
181
pub fn left_sample_array ( & self ) -> Result < & [ NodeId ] , TskitError > {
173
182
err_if_not_tracking_samples ! (
174
183
self . flags,
175
- tree_array_slice! ( self , left_sample, ( * self . as_ptr ( ) ) . num_nodes )
184
+ sys :: tree_array_slice( self . as_ref ( ) . left_sample, self . array_len )
176
185
)
177
186
}
178
187
@@ -209,7 +218,7 @@ impl TreeInterface {
209
218
pub fn right_sample_array ( & self ) -> Result < & [ NodeId ] , TskitError > {
210
219
err_if_not_tracking_samples ! (
211
220
self . flags,
212
- tree_array_slice! ( self , right_sample, ( * self . as_ptr ( ) ) . num_nodes )
221
+ sys :: tree_array_slice( self . as_ref ( ) . right_sample, self . array_len )
213
222
)
214
223
}
215
224
@@ -230,7 +239,7 @@ impl TreeInterface {
230
239
/// }
231
240
/// ```
232
241
pub fn left_sib_array ( & self ) -> & [ NodeId ] {
233
- tree_array_slice ! ( self , left_sib, self . array_len)
242
+ sys :: tree_array_slice ( self . as_ref ( ) . left_sib , self . array_len )
234
243
}
235
244
236
245
/// # Failing examples
@@ -250,7 +259,7 @@ impl TreeInterface {
250
259
/// }
251
260
/// ```
252
261
pub fn right_sib_array ( & self ) -> & [ NodeId ] {
253
- tree_array_slice ! ( self , right_sib, self . array_len)
262
+ sys :: tree_array_slice ( self . as_ref ( ) . right_sib , self . array_len )
254
263
}
255
264
256
265
/// # Failing examples
@@ -270,7 +279,7 @@ impl TreeInterface {
270
279
/// }
271
280
/// ```
272
281
pub fn left_child_array ( & self ) -> & [ NodeId ] {
273
- tree_array_slice ! ( self , left_child, self . array_len)
282
+ sys :: tree_array_slice ( self . as_ref ( ) . left_child , self . array_len )
274
283
}
275
284
276
285
/// # Failing examples
@@ -290,7 +299,7 @@ impl TreeInterface {
290
299
/// }
291
300
/// ```
292
301
pub fn right_child_array ( & self ) -> & [ NodeId ] {
293
- tree_array_slice ! ( self , right_child, self . array_len)
302
+ sys :: tree_array_slice ( self . as_ref ( ) . right_child , self . array_len )
294
303
}
295
304
296
305
// error if we are not tracking samples,
@@ -396,7 +405,7 @@ impl TreeInterface {
396
405
pub fn sample_nodes ( & self ) -> & [ NodeId ] {
397
406
let num_samples =
398
407
unsafe { ll_bindings:: tsk_treeseq_get_num_samples ( ( * self . as_ptr ( ) ) . tree_sequence ) } ;
399
- tree_array_slice ! ( self , samples, num_samples)
408
+ sys :: tree_array_slice ( self . as_ref ( ) . samples , num_samples)
400
409
}
401
410
402
411
/// Return an [`Iterator`] from the node `u` to the root of the tree,
0 commit comments