@@ -3,6 +3,7 @@ use std::vec;
3
3
4
4
use crate :: error:: TskitError ;
5
5
use crate :: sys:: bindings as ll_bindings;
6
+ use crate :: sys:: TableCollection as LLTableCollection ;
6
7
use crate :: types:: Bookmark ;
7
8
use crate :: IndividualTableSortOptions ;
8
9
use crate :: Position ;
@@ -54,18 +55,11 @@ use mbox::MBox;
54
55
/// ```
55
56
///
56
57
pub struct TableCollection {
57
- inner : MBox < ll_bindings :: tsk_table_collection_t > ,
58
+ inner : LLTableCollection ,
58
59
idmap : Vec < NodeId > ,
59
60
views : crate :: table_views:: TableViews ,
60
61
}
61
62
62
- impl Drop for TableCollection {
63
- fn drop ( & mut self ) {
64
- let rv = unsafe { tsk_table_collection_free ( self . as_mut_ptr ( ) ) } ;
65
- assert_eq ! ( rv, 0 ) ;
66
- }
67
- }
68
-
69
63
/// Returns a pointer to an uninitialized tsk_table_collection_t
70
64
pub ( crate ) fn uninit_table_collection ( ) -> MBox < ll_bindings:: tsk_table_collection_t > {
71
65
let temp = unsafe {
@@ -101,26 +95,12 @@ impl TableCollection {
101
95
expected : "sequence_length >= 0.0" . to_string ( ) ,
102
96
} ) ;
103
97
}
104
- let mut mbox = uninit_table_collection ( ) ;
105
- let rv = unsafe { ll_bindings:: tsk_table_collection_init ( & mut * mbox, 0 ) } ;
106
- if rv < 0 {
107
- return Err ( crate :: error:: TskitError :: ErrorCode { code : rv } ) ;
108
- }
109
- let views = crate :: table_views:: TableViews :: new_from_mbox_table_collection ( & mut mbox) ?;
110
- // AHA?
111
- assert ! ( std:: ptr:: eq(
112
- & mbox. as_ref( ) . edges as * const ll_bindings:: tsk_edge_table_t,
113
- views. edges( ) . as_ref( ) as * const ll_bindings:: tsk_edge_table_t
114
- ) ) ;
115
- let mut tables = Self {
116
- inner : mbox,
98
+ let inner = LLTableCollection :: new ( sequence_length. into ( ) ) ;
99
+ Ok ( Self {
100
+ inner,
117
101
idmap : vec ! [ ] ,
118
- views,
119
- } ;
120
- unsafe {
121
- ( * tables. as_mut_ptr ( ) ) . sequence_length = f64:: from ( sequence_length) ;
122
- }
123
- Ok ( tables)
102
+ view : TableViews :
103
+ } )
124
104
}
125
105
126
106
/// # Safety
@@ -1279,11 +1259,11 @@ impl TableCollection {
1279
1259
1280
1260
/// Pointer to the low-level C type.
1281
1261
pub fn as_ptr ( & self ) -> * const ll_bindings:: tsk_table_collection_t {
1282
- & * self . inner
1262
+ self . inner . as_ptr ( )
1283
1263
}
1284
1264
1285
1265
/// Mutable pointer to the low-level C type.
1286
1266
pub fn as_mut_ptr ( & mut self ) -> * mut ll_bindings:: tsk_table_collection_t {
1287
- & mut * self . inner
1267
+ self . inner . as_mut_ptr ( )
1288
1268
}
1289
1269
}
0 commit comments