Skip to content

Commit 80f51bb

Browse files
committed
set_populations
1 parent 3577177 commit 80f51bb

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/table_collection.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,6 @@ impl TableCollection {
10471047
handle_tsk_return_value!(rv)
10481048
}
10491049

1050-
10511050
/// Set the migration table from an [`OwnedMigrationTable`](`crate::OwnedSiteTable`)
10521051
///
10531052
/// # Errors
@@ -1084,6 +1083,36 @@ impl TableCollection {
10841083
};
10851084
handle_tsk_return_value!(rv)
10861085
}
1086+
1087+
/// Set the population table from an [`OwnedPopulationTable`](`crate::OwnedSiteTable`)
1088+
///
1089+
/// # Errors
1090+
///
1091+
/// Any errors from the C API propagate.
1092+
///
1093+
/// # Example
1094+
///
1095+
/// ```rust
1096+
/// # use tskit::TableAccess;
1097+
/// let mut tables = tskit::TableCollection::new(1.0).unwrap();
1098+
/// let mut populations = tskit::OwnedPopulationTable::default();
1099+
/// populations.add_row().unwrap();
1100+
/// tables.set_populations(&populations).unwrap();
1101+
/// assert_eq!(tables.populations().num_rows(), 1);
1102+
/// # populations.clear().unwrap();
1103+
/// # assert_eq!(populations.num_rows(), 0);
1104+
/// ```
1105+
pub fn set_populations(&mut self, populations: &crate::OwnedPopulationTable) -> TskReturnValue {
1106+
let rv = unsafe {
1107+
ll_bindings::tsk_population_table_set_columns(
1108+
&mut (*self.inner).populations,
1109+
(*populations.as_ptr()).num_rows,
1110+
(*populations.as_ptr()).metadata,
1111+
(*populations.as_ptr()).metadata_offset,
1112+
)
1113+
};
1114+
handle_tsk_return_value!(rv)
1115+
}
10871116
}
10881117

10891118
impl TableAccess for TableCollection {

0 commit comments

Comments
 (0)