Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/sys/treeseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ impl TreeSequence {
Ok(Self(tsk))
}

// # Safety
//
// `tables` must be an initialized `tsk_table_collection_t`
pub unsafe fn new_owning_from_nonnull(
treeseq: std::ptr::NonNull<tsk_treeseq_t>,
) -> Self {
Self(TskBox::new_init_owning_from_ptr(treeseq))
}

pub fn as_ref(&self) -> &bindings::tsk_treeseq_t {
self.0.as_ref()
}
Expand Down
13 changes: 13 additions & 0 deletions src/trees/treeseq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,19 @@ impl TreeSequence {
) -> impl crate::TableColumn<crate::EdgeId, crate::EdgeId> + '_ {
crate::table_column::OpaqueTableColumn(self.edge_removal_order())
}

#[cfg(feature = "unsafe_init")]
pub unsafe fn new_from_raw(
ptr: std::ptr::NonNull<ll_bindings::tsk_treeseq_t>,
) -> Result<Self, TskitError> {
let tables = unsafe {
TableCollection::new_from_ll(sys::TableCollection::new_borrowed(
std::ptr::NonNull::new(ptr.as_ref().tables).unwrap(),
))
}?;
let inner = sys::TreeSequence::new(tables, 0.into())?;
Ok(Self{inner, tables })
}
}

impl TryFrom<TableCollection> for TreeSequence {
Expand Down
Loading