Skip to content

Commit 9d91f9e

Browse files
authored
feat: TableViews can now lend &mut for all table types. (#455)
1 parent bd0655c commit 9d91f9e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

src/table_collection.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,29 @@ impl TableCollection {
12441244
to self.views {
12451245
/// Get mutable reference to the [``NodeTable``](crate::NodeTable).
12461246
pub fn nodes_mut(&mut self) -> &mut crate::NodeTable;
1247+
1248+
/// Get mutable reference to the [``EdgeTable``](crate::EdgeTable).
1249+
pub fn edges_mut(&mut self) -> &mut crate::EdgeTable;
1250+
1251+
/// Get mutable reference to the [``SiteTable``](crate::SiteTable).
1252+
pub fn sites_mut(&mut self) -> &mut crate::SiteTable;
1253+
1254+
/// Get mutable reference to the [``MutationTable``](crate::MutationTable).
1255+
pub fn mutations_mut(&mut self) -> &mut crate::MutationTable;
1256+
1257+
/// Get mutable reference to the [``IndividualTable``](crate::IndividualTable).
1258+
pub fn individuals_mut(&mut self) -> &mut crate::IndividualTable;
1259+
1260+
/// Get mutable reference to the [``PopulationTable``](crate::PopulationTable).
1261+
pub fn populations_mut(&mut self) -> &mut crate::PopulationTable;
1262+
1263+
/// Get mutable reference to the [``MigrationTable``](crate::PopulationTable).
1264+
pub fn migrations_mut(&mut self) -> &mut crate::MigrationTable;
1265+
1266+
#[cfg(feature="provenance")]
1267+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
1268+
/// Get mutable reference to the [``ProvenanceTable``](crate::ProvenanceTable).
1269+
pub fn provenances_mut(&mut self) -> &mut crate::provenance::ProvenanceTable;
12471270
}
12481271
}
12491272

@@ -1259,3 +1282,17 @@ impl TableCollection {
12591282
&mut *self.inner
12601283
}
12611284
}
1285+
1286+
#[test]
1287+
fn test_mutable_node_references() {
1288+
let mut tables = crate::TableCollection::new(10.0).unwrap();
1289+
let _nodes: &mut crate::NodeTable = tables.nodes_mut();
1290+
let _edges: &mut crate::EdgeTable = tables.edges_mut();
1291+
let _sites: &mut crate::SiteTable = tables.sites_mut();
1292+
let _mutations: &mut crate::MutationTable = tables.mutations_mut();
1293+
let _individuals: &mut crate::IndividualTable = tables.individuals_mut();
1294+
let _populations: &mut crate::PopulationTable = tables.populations_mut();
1295+
let _migrations: &mut crate::MigrationTable = tables.migrations_mut();
1296+
#[cfg(feature = "provenance")]
1297+
let _provenances: &mut crate::provenance::ProvenanceTable = tables.provenances_mut();
1298+
}

src/table_views.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ impl TableViews {
9090
&self.edges
9191
}
9292

93+
/// Get mutable reference to the [``EdgeTable``](crate::EdgeTable).
94+
pub fn edges_mut(&mut self) -> &mut EdgeTable {
95+
&mut self.edges
96+
}
97+
9398
/// Get reference to the [``NodeTable``](crate::NodeTable).
9499
pub fn nodes(&self) -> &NodeTable {
95100
&self.nodes
@@ -105,33 +110,65 @@ impl TableViews {
105110
&self.sites
106111
}
107112

113+
/// Get mutable reference to the [``SiteTable``](crate::SiteTable).
114+
pub fn sites_mut(&mut self) -> &mut SiteTable {
115+
&mut self.sites
116+
}
117+
108118
/// Get reference to the [``MutationTable``](crate::MutationTable).
109119
pub fn mutations(&self) -> &MutationTable {
110120
&self.mutations
111121
}
112122

123+
/// Get mutable reference to the [``MutationTable``](crate::MutationTable).
124+
pub fn mutations_mut(&mut self) -> &mut MutationTable {
125+
&mut self.mutations
126+
}
127+
113128
/// Get reference to the [``IndividualTable``](crate::IndividualTable).
114129
pub fn individuals(&self) -> &IndividualTable {
115130
&self.individuals
116131
}
117132

133+
/// Get mutable reference to the [``IndividualTable``](crate::IndividualTable).
134+
pub fn individuals_mut(&mut self) -> &mut IndividualTable {
135+
&mut self.individuals
136+
}
137+
118138
/// Get reference to the [``PopulationTable``](crate::PopulationTable).
119139
pub fn populations(&self) -> &PopulationTable {
120140
&self.populations
121141
}
122142

143+
/// Get mutable reference to the [``PopulationTable``](crate::PopulationTable).
144+
pub fn populations_mut(&mut self) -> &mut PopulationTable {
145+
&mut self.populations
146+
}
147+
123148
/// Get reference to the [``MigrationTable``](crate::MigrationTable).
124149
pub fn migrations(&self) -> &MigrationTable {
125150
&self.migrations
126151
}
127152

153+
/// Get mutable reference to the [``MigrationTable``](crate::MigrationTable).
154+
pub fn migrations_mut(&mut self) -> &mut MigrationTable {
155+
&mut self.migrations
156+
}
157+
128158
#[cfg(feature = "provenance")]
129159
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
130160
/// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
131161
pub fn provenances(&self) -> &ProvenanceTable {
132162
&self.provenances
133163
}
134164

165+
#[cfg(feature = "provenance")]
166+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
167+
/// Get mutable reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
168+
pub fn provenances_mut(&mut self) -> &mut ProvenanceTable {
169+
&mut self.provenances
170+
}
171+
135172
/// Return an iterator over the edges.
136173
pub fn edges_iter(&self) -> impl Iterator<Item = crate::EdgeTableRow> + '_ {
137174
self.edges.iter()

0 commit comments

Comments
 (0)