Skip to content

Commit

Permalink
Add prelude.rs (#119)
Browse files Browse the repository at this point in the history
Remove macro to use all public traits (See PR #110)

Closes #118
  • Loading branch information
molpopgen authored May 12, 2021
1 parent a592126 commit 6fa2057
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/tree_traversals.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::{value_t_or_exit, App, Arg};
use streaming_iterator::StreamingIterator; // Required for tree iteration
use tskit::prelude::*;

// "Manual" traversal from samples to root
fn traverse_upwards(tree: &tskit::Tree) {
Expand Down
13 changes: 0 additions & 13 deletions src/_macros.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
#![macro_use]

/// Convenience macro issuing `use` for all public traits.
#[macro_export]
macro_rules! enable_tskit_traits {
() => {
use $crate::metadata::MetadataRoundtrip;
#[cfg(feature = "provenance")]
use $crate::provenance::Provenance;
use $crate::NodeListGenerator;
use $crate::TableAccess;
use $crate::TskitTypeAccess;
};
}

#[doc(hidden)]
macro_rules! handle_tsk_return_value {
($code: expr) => {{
Expand Down
16 changes: 16 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@
//! * Tree lifetimes are tied to that of the parent tree sequence.
//! * Table objects ([`NodeTable`], etc..) are only represented by non-owning, immutable types.
//!
//! ## Prelude
//!
//! The [`prelude`] module contains definitions that are difficult/annoying to live without.
//! In particuar, this module exports various traits that make it so that client code does
//! not have to `use` them a la carte.
//!
//! We recomment that client code import all symbols from this module:
//!
//! ```
//! use tskit::prelude::*;
//! ```
//!
//! The various documentation examples manually `use` each trait both in order
//! to illustrate which traits are needed and to serve as doc tests.
//!
//! # Optional features
//!
//! Some features are optional, and are activated by requesting them in your `Cargo.toml` file.
Expand Down Expand Up @@ -60,6 +75,7 @@ mod migration_table;
mod mutation_table;
mod node_table;
mod population_table;
pub mod prelude;
mod site_table;
mod table_collection;
mod table_iterator;
Expand Down
12 changes: 12 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Export commonly-use types and traits
pub use crate::tsk_flags_t;
pub use crate::tsk_id_t;
pub use crate::tsk_size_t;
pub use crate::NodeListGenerator;
pub use crate::TableAccess;
pub use crate::TskitTypeAccess;
pub use crate::TSK_NODE_IS_SAMPLE;
pub use crate::TSK_NULL;
pub use streaming_iterator::DoubleEndedStreamingIterator;
pub use streaming_iterator::StreamingIterator;

0 comments on commit 6fa2057

Please sign in to comment.