Accessing table columns
We can access table rows using either the relevant newtype or i32
(which is identical to the tskit-c
typedef tsk_id_t
).
The following snippet adds and edge and then validates the data for that row of the table:
if let Ok(edge_id) = tables.add_edge(left, right, parent, child) {
// Take a reference to an edge table (& tskit::EdgeTable)
let edges = tables.edges();
if let Some(p) = edges.parent(edge_id) {
assert_eq!(p, parent);
}
if let Some(c) = edges.child(edge_id) {
assert_eq!(c, child);
}
if let Some(l) = edges.left(edge_id) {
assert_eq!(l, left);
}
if let Some(r) = edges.right(edge_id) {
assert_eq!(r, right);
}
} else {
panic!("that should have worked...");
}
The return type of the getters is the Option
enum. The None
variant is returned when row indexes are out of range:
assert!(tables.edges().parent(tskit::EdgeId::NULL).is_none());