Skip to content

Commit dc42784

Browse files
committed
basic tables pass
1 parent c185e03 commit dc42784

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

src/edge_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl EdgeTable {
308308
right: self.right(r)?,
309309
parent: self.parent(r)?,
310310
child: self.child(r)?,
311-
metadata: Some(self.raw_metadata(r.into())?),
311+
metadata: self.raw_metadata(r.into()),
312312
};
313313
Some(view)
314314
}

src/population_table.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,17 @@ impl PopulationTable {
203203
/// * `Some(row view)` if `r` is valid
204204
/// * `None` otherwise
205205
pub fn row_view<P: Into<PopulationId> + Copy>(&self, r: P) -> Option<PopulationTableRowView> {
206-
let view = PopulationTableRowView {
207-
table: self,
208-
id: r.into(),
209-
metadata: Some(self.raw_metadata(r.into())?),
210-
};
211-
Some(view)
206+
match SizeType::try_from(r.into().0).ok() {
207+
Some(row) if row < self.num_rows() => {
208+
let view = PopulationTableRowView {
209+
table: self,
210+
id: r.into(),
211+
metadata: self.raw_metadata(r.into()),
212+
};
213+
Some(view)
214+
}
215+
_ => None,
216+
}
212217
}
213218
}
214219

src/site_table.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,27 @@ impl SiteTable {
242242
let ri = r.into().0;
243243
table_row_access!(ri, self, make_site_table_row)
244244
}
245+
246+
/// Return a view of row `r` of the table.
247+
///
248+
/// # Parameters
249+
///
250+
/// * `r`: the row id.
251+
///
252+
/// # Returns
253+
///
254+
/// * `Some(row view)` if `r` is valid
255+
/// * `None` otherwise
256+
pub fn row_view<S: Into<SiteId> + Copy>(&self, r: S) -> Option<SiteTableRowView> {
257+
let view = SiteTableRowView {
258+
table: self,
259+
id: r.into(),
260+
position: self.position(r)?,
261+
ancestral_state: self.ancestral_state(r),
262+
metadata: self.raw_metadata(r.into()),
263+
};
264+
Some(view)
265+
}
245266
}
246267

247268
build_owned_table_type!(

0 commit comments

Comments
 (0)