Skip to content

Commit b0abdfa

Browse files
authored
impl TryFrom<TableCollection> for TreeSequence (#236)
1 parent 71e927a commit b0abdfa

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/trees.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ impl TreeSequence {
981981
/// ```
982982
/// let mut tables = tskit::TableCollection::new(1000.).unwrap();
983983
/// tables.build_index();
984-
/// let tree_sequence = tskit::TreeSequence::new(tables, tskit::TreeSequenceFlags::default()).unwrap();
984+
/// let tree_sequence = tskit::TreeSequence::try_from(tables).unwrap();
985985
/// ```
986986
///
987987
/// The following may be preferred to the previous example, and more closely
@@ -997,8 +997,7 @@ impl TreeSequence {
997997
///
998998
/// ```should_panic
999999
/// let mut tables = tskit::TableCollection::new(1000.).unwrap();
1000-
/// let tree_sequence = tskit::TreeSequence::new(tables,
1001-
/// tskit::TreeSequenceFlags::default()).unwrap();
1000+
/// let tree_sequence = tskit::TreeSequence::try_from(tables).unwrap();
10021001
/// ```
10031002
///
10041003
/// ## Note
@@ -1269,6 +1268,14 @@ impl TreeSequence {
12691268
}
12701269
}
12711270

1271+
impl TryFrom<TableCollection> for TreeSequence {
1272+
type Error = TskitError;
1273+
1274+
fn try_from(value: TableCollection) -> Result<Self, Self::Error> {
1275+
Self::new(value, TreeSequenceFlags::default())
1276+
}
1277+
}
1278+
12721279
impl TableAccess for TreeSequence {
12731280
fn edges(&self) -> EdgeTable {
12741281
EdgeTable::new_from_table(unsafe { &(*(*self.inner).tables).edges })

0 commit comments

Comments
 (0)