Skip to content

Commit 3577177

Browse files
committed
set_migrations
1 parent 798e2dd commit 3577177

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

src/table_collection.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ impl TableCollection {
10081008
handle_tsk_return_value!(rv)
10091009
}
10101010

1011-
/// Set the individual table from an [`OwnedMutationTable`](`crate::OwnedSiteTable`)
1011+
/// Set the individual table from an [`OwnedIndividualTable`](`crate::OwnedSiteTable`)
10121012
///
10131013
/// # Errors
10141014
///
@@ -1024,7 +1024,7 @@ impl TableCollection {
10241024
/// tables.set_individuals(&individuals).unwrap();
10251025
/// assert_eq!(tables.individuals().num_rows(), 1);
10261026
/// let expected = vec![tskit::Location::from(0.1), tskit::Location::from(10.0)];
1027-
/// assert_eq!(tables.individuals().location(0).unwrap(), Some(expected));
1027+
/// assert_eq!(tables.individuals().location(0).unwrap(), Some(expected.as_slice()));
10281028
/// # individuals.clear().unwrap();
10291029
/// # assert_eq!(individuals.num_rows(), 0);
10301030
/// ```
@@ -1047,7 +1047,43 @@ impl TableCollection {
10471047
handle_tsk_return_value!(rv)
10481048
}
10491049

1050-
pub fn set_migrations(&mut self, migrations: &crate::OwnedMigrationTable) -> TskReturnValue {}
1050+
1051+
/// Set the migration table from an [`OwnedMigrationTable`](`crate::OwnedSiteTable`)
1052+
///
1053+
/// # Errors
1054+
///
1055+
/// Any errors from the C API propagate.
1056+
///
1057+
/// # Example
1058+
///
1059+
/// ```rust
1060+
/// # use tskit::TableAccess;
1061+
/// let mut tables = tskit::TableCollection::new(1.0).unwrap();
1062+
/// let mut migrations = tskit::OwnedMigrationTable::default();
1063+
/// migrations.add_row((0.25, 0.37), 1, (0, 1), 111.0).unwrap();
1064+
/// tables.set_migrations(&migrations).unwrap();
1065+
/// assert_eq!(tables.migrations().num_rows(), 1);
1066+
/// assert_eq!(tables.migrations().time(0).unwrap(), 111.0);
1067+
/// # migrations.clear().unwrap();
1068+
/// # assert_eq!(migrations.num_rows(), 0);
1069+
/// ```
1070+
pub fn set_migrations(&mut self, migrations: &crate::OwnedMigrationTable) -> TskReturnValue {
1071+
let rv = unsafe {
1072+
ll_bindings::tsk_migration_table_set_columns(
1073+
&mut (*self.inner).migrations,
1074+
(*migrations.as_ptr()).num_rows,
1075+
(*migrations.as_ptr()).left,
1076+
(*migrations.as_ptr()).right,
1077+
(*migrations.as_ptr()).node,
1078+
(*migrations.as_ptr()).source,
1079+
(*migrations.as_ptr()).dest,
1080+
(*migrations.as_ptr()).time,
1081+
(*migrations.as_ptr()).metadata,
1082+
(*migrations.as_ptr()).metadata_offset,
1083+
)
1084+
};
1085+
handle_tsk_return_value!(rv)
1086+
}
10511087
}
10521088

10531089
impl TableAccess for TableCollection {

0 commit comments

Comments
 (0)