Skip to content

refactor: remove TskitTypeAccess trait #411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
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
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,6 @@ pub use site_table::{OwningSiteTable, SiteTable, SiteTableRow};
pub use table_collection::TableCollection;
pub use traits::IndividualLocation;
pub use traits::IndividualParents;
pub use traits::TskitTypeAccess;
pub use tree_interface::{NodeTraversalOrder, TreeInterface};
pub use trees::{Tree, TreeSequence};

Expand Down
1 change: 0 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Export commonly-use types and traits

pub use crate::tsk_flags_t;
pub use crate::TskitTypeAccess;
pub use crate::TSK_NODE_IS_SAMPLE;
pub use streaming_iterator::DoubleEndedStreamingIterator;
pub use streaming_iterator::StreamingIterator;
Expand Down
21 changes: 10 additions & 11 deletions src/table_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::TableOutputOptions;
use crate::TableSortOptions;
use crate::TreeSequenceFlags;
use crate::TskReturnValue;
use crate::TskitTypeAccess;
use crate::{tsk_id_t, tsk_size_t};
use crate::{EdgeId, NodeId};
use ll_bindings::tsk_table_collection_free;
Expand Down Expand Up @@ -59,16 +58,6 @@ pub struct TableCollection {
views: crate::table_views::TableViews,
}

impl TskitTypeAccess<ll_bindings::tsk_table_collection_t> for TableCollection {
fn as_ptr(&self) -> *const ll_bindings::tsk_table_collection_t {
&*self.inner
}

fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_table_collection_t {
&mut *self.inner
}
}

impl Drop for TableCollection {
fn drop(&mut self) {
let rv = unsafe { tsk_table_collection_free(self.as_mut_ptr()) };
Expand Down Expand Up @@ -1229,4 +1218,14 @@ impl TableCollection {
}

delegate_table_view_api!();

/// Pointer to the low-level C type.
pub fn as_ptr(&self) -> *const ll_bindings::tsk_table_collection_t {
&*self.inner
}

/// Mutable pointer to the low-level C type.
pub fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_table_collection_t {
&mut *self.inner
}
}
8 changes: 0 additions & 8 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
//! Traits related to user-facing types

/// Provide pointer access to underlying C types
pub trait TskitTypeAccess<T> {
/// Return const pointer
fn as_ptr(&self) -> *const T;
/// Return mutable pointer
fn as_mut_ptr(&mut self) -> *mut T;
}

/// Abstraction of individual location.
///
/// This trait exists to streamline the API of
Expand Down
21 changes: 10 additions & 11 deletions src/tree_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::SizeType;
use crate::Time;
use crate::TreeFlags;
use crate::TskitError;
use crate::TskitTypeAccess;
use std::ptr::NonNull;

pub struct TreeInterface {
Expand All @@ -17,16 +16,6 @@ pub struct TreeInterface {
flags: TreeFlags,
}

impl TskitTypeAccess<ll_bindings::tsk_tree_t> for TreeInterface {
fn as_ptr(&self) -> *const ll_bindings::tsk_tree_t {
self.non_owned_pointer.as_ptr()
}

fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_tree_t {
self.non_owned_pointer.as_ptr()
}
}

impl TreeInterface {
pub(crate) fn new(
non_owned_pointer: NonNull<ll_bindings::tsk_tree_t>,
Expand All @@ -42,6 +31,16 @@ impl TreeInterface {
}
}

/// Pointer to the low-level C type.
pub fn as_ptr(&self) -> *const ll_bindings::tsk_tree_t {
self.non_owned_pointer.as_ptr()
}

/// Mutable pointer to the low-level C type.
pub fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_tree_t {
self.non_owned_pointer.as_ptr()
}

pub fn flags(&self) -> TreeFlags {
self.flags
}
Expand Down
21 changes: 10 additions & 11 deletions src/trees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::TreeFlags;
use crate::TreeInterface;
use crate::TreeSequenceFlags;
use crate::TskReturnValue;
use crate::TskitTypeAccess;
use crate::{tsk_id_t, tsk_size_t, TableCollection};
use ll_bindings::tsk_tree_free;
use std::ptr::NonNull;
Expand Down Expand Up @@ -192,16 +191,6 @@ pub struct TreeSequence {
unsafe impl Send for TreeSequence {}
unsafe impl Sync for TreeSequence {}

impl TskitTypeAccess<ll_bindings::tsk_treeseq_t> for TreeSequence {
fn as_ptr(&self) -> *const ll_bindings::tsk_treeseq_t {
&self.inner
}

fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_treeseq_t {
&mut self.inner
}
}

impl Drop for TreeSequence {
fn drop(&mut self) {
let rv = unsafe { ll_bindings::tsk_treeseq_free(&mut self.inner) };
Expand Down Expand Up @@ -270,6 +259,16 @@ impl TreeSequence {
})
}

/// Pointer to the low-level C type.
pub fn as_ptr(&self) -> *const ll_bindings::tsk_treeseq_t {
&self.inner
}

/// Mutable pointer to the low-level C type.
pub fn as_mut_ptr(&mut self) -> *mut ll_bindings::tsk_treeseq_t {
&mut self.inner
}

/// Dump the tree sequence to file.
///
/// # Note
Expand Down