Skip to content

Commit 6fa2057

Browse files
authored
Add prelude.rs (#119)
Remove macro to use all public traits (See PR #110) Closes #118
1 parent a592126 commit 6fa2057

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

examples/tree_traversals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clap::{value_t_or_exit, App, Arg};
2-
use streaming_iterator::StreamingIterator; // Required for tree iteration
2+
use tskit::prelude::*;
33

44
// "Manual" traversal from samples to root
55
fn traverse_upwards(tree: &tskit::Tree) {

src/_macros.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
#![macro_use]
22

3-
/// Convenience macro issuing `use` for all public traits.
4-
#[macro_export]
5-
macro_rules! enable_tskit_traits {
6-
() => {
7-
use $crate::metadata::MetadataRoundtrip;
8-
#[cfg(feature = "provenance")]
9-
use $crate::provenance::Provenance;
10-
use $crate::NodeListGenerator;
11-
use $crate::TableAccess;
12-
use $crate::TskitTypeAccess;
13-
};
14-
}
15-
163
#[doc(hidden)]
174
macro_rules! handle_tsk_return_value {
185
($code: expr) => {{

src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@
2424
//! * Tree lifetimes are tied to that of the parent tree sequence.
2525
//! * Table objects ([`NodeTable`], etc..) are only represented by non-owning, immutable types.
2626
//!
27+
//! ## Prelude
28+
//!
29+
//! The [`prelude`] module contains definitions that are difficult/annoying to live without.
30+
//! In particuar, this module exports various traits that make it so that client code does
31+
//! not have to `use` them a la carte.
32+
//!
33+
//! We recomment that client code import all symbols from this module:
34+
//!
35+
//! ```
36+
//! use tskit::prelude::*;
37+
//! ```
38+
//!
39+
//! The various documentation examples manually `use` each trait both in order
40+
//! to illustrate which traits are needed and to serve as doc tests.
41+
//!
2742
//! # Optional features
2843
//!
2944
//! Some features are optional, and are activated by requesting them in your `Cargo.toml` file.
@@ -60,6 +75,7 @@ mod migration_table;
6075
mod mutation_table;
6176
mod node_table;
6277
mod population_table;
78+
pub mod prelude;
6379
mod site_table;
6480
mod table_collection;
6581
mod table_iterator;

src/prelude.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//! Export commonly-use types and traits
2+
3+
pub use crate::tsk_flags_t;
4+
pub use crate::tsk_id_t;
5+
pub use crate::tsk_size_t;
6+
pub use crate::NodeListGenerator;
7+
pub use crate::TableAccess;
8+
pub use crate::TskitTypeAccess;
9+
pub use crate::TSK_NODE_IS_SAMPLE;
10+
pub use crate::TSK_NULL;
11+
pub use streaming_iterator::DoubleEndedStreamingIterator;
12+
pub use streaming_iterator::StreamingIterator;

0 commit comments

Comments
 (0)