@@ -4,6 +4,7 @@ use crate::IndividualFlags;
4
4
use crate :: IndividualId ;
5
5
use crate :: Location ;
6
6
use crate :: { tsk_id_t, tsk_size_t, TskitError } ;
7
+ use ll_bindings:: { tsk_individual_table_free, tsk_individual_table_init} ;
7
8
8
9
/// Row of a [`IndividualTable`]
9
10
pub struct IndividualTableRow {
@@ -278,3 +279,59 @@ impl<'a> IndividualTable<'a> {
278
279
table_row_access ! ( ri. 0 , self , make_individual_table_row)
279
280
}
280
281
}
282
+
283
+ build_owned_table_type ! (
284
+ /// A standalone individual table that owns its data.
285
+ ///
286
+ /// # Examples
287
+ ///
288
+ /// ```
289
+ /// use tskit::OwnedIndividualTable;
290
+ ///
291
+ /// let mut individuals = OwnedIndividualTable::default();
292
+ /// let rowid = individuals.add_row(0, None, None).unwrap();
293
+ /// assert_eq!(rowid, 0);
294
+ /// assert_eq!(individuals.num_rows(), 1);
295
+ /// ```
296
+ ///
297
+ /// An example with metadata.
298
+ /// This requires the cargo feature `"derive"` for `tskit`.
299
+ ///
300
+ /// ```
301
+ /// # #[cfg(any(feature="doc", feature="derive"))] {
302
+ /// use tskit::OwnedIndividualTable;
303
+ ///
304
+ /// #[derive(serde::Serialize,
305
+ /// serde::Deserialize,
306
+ /// tskit::metadata::IndividualMetadata)]
307
+ /// #[serializer("serde_json")]
308
+ /// struct IndividualMetadata {
309
+ /// value: i32,
310
+ /// }
311
+ ///
312
+ /// let metadata = IndividualMetadata{value: 42};
313
+ ///
314
+ /// let mut individuals = OwnedIndividualTable::default();
315
+ ///
316
+ /// let rowid = individuals.add_row_with_metadata(0, None, None, &metadata).unwrap();
317
+ /// assert_eq!(rowid, 0);
318
+ ///
319
+ /// if let Some(decoded) = individuals.metadata::<IndividualMetadata>(rowid).unwrap() {
320
+ /// assert_eq!(decoded.value, 42);
321
+ /// } else {
322
+ /// panic!("hmm...we expected some metadata!");
323
+ /// }
324
+ ///
325
+ /// # }
326
+ /// ```
327
+ => OwnedIndividualTable ,
328
+ IndividualTable ,
329
+ tsk_individual_table_t,
330
+ tsk_individual_table_init,
331
+ tsk_individual_table_free
332
+ ) ;
333
+
334
+ impl OwnedIndividualTable {
335
+ individual_table_add_row ! ( => add_row, self , * self . table) ;
336
+ individual_table_add_row_with_metadata ! ( => add_row_with_metadata, self , * self . table) ;
337
+ }
0 commit comments