Skip to content

Commit ff1c7ce

Browse files
authored
Add Provenance trait as optional feature (#98).
1 parent 0fdd300 commit ff1c7ce

File tree

7 files changed

+394
-30
lines changed

7 files changed

+394
-30
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ on:
66
name: CI
77

88
jobs:
9-
build-linux:
10-
runs-on: ubuntu-latest
9+
run-tests:
10+
runs-on: ${{ matrix.os }}
1111
#container:
1212
# image: ubuntu:20.10
1313
strategy:
1414
matrix:
15+
os: [ubuntu-latest, macos-latest]
1516
rust:
1617
- stable
1718
- beta
@@ -26,43 +27,27 @@ jobs:
2627
token: ${{ secrets.GITHUB_TOKEN }}
2728
submodules: recursive
2829
- run: sudo apt-get update -y
30+
if: matrix.os == 'ubuntu-latest'
2931
- uses: actions-rs/toolchain@v1
3032
with:
3133
toolchain: ${{ matrix.rust }}
3234
override: true
3335
- name: cargo check
34-
run: cargo check
36+
run: cargo check
3537
- name: cargo check examples
3638
run: cargo check --examples
39+
- name: cargo check all features
40+
run: cargo check --all-features
41+
- name: cargo check examples w/all featurse
42+
run: cargo check --examples --all-features
3743
- name: run tests
3844
run: |
3945
cargo test
4046
cargo test --examples
41-
42-
build-osx:
43-
runs-on: macos-latest
44-
strategy:
45-
matrix:
46-
rust:
47-
- stable
48-
- beta
49-
steps:
50-
- uses: actions/checkout@v2
51-
with:
52-
token: ${{ secrets.GITHUB_TOKEN }}
53-
submodules: recursive
54-
- uses: actions-rs/toolchain@v1
55-
with:
56-
toolchain: ${{ matrix.rust }}
57-
override: true
58-
- name: cargo check
59-
run: cargo check
60-
- name: cargo check examples
61-
run: cargo check --examples
62-
- name: run tests
47+
- name: run tests (all featurss)
6348
run: |
64-
cargo test
65-
cargo test --examples
49+
cargo test --all-features
50+
cargo test --all-features --examples
6651
6752
fmt:
6853
name: rust fmt
@@ -93,4 +78,6 @@ jobs:
9378
override: true
9479
- run: rustup component add clippy
9580
- name: clippy (all targets)
81+
run: cargo clippy --all-targets --all-features -- -D warnings
82+
- name: clippy (all targets, all features)
9683
run: cargo clippy --all-targets -- -D warnings

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ thiserror = "1.0"
1616
libc = "0.2.81"
1717
streaming-iterator = "0.1.5"
1818
bitflags = "1.2.1"
19+
chrono = {version = "0.4.19", optional = true}
1920

2021
[dev-dependencies]
2122
clap = "~2.27.0"
@@ -29,6 +30,12 @@ bindgen = "0.57.0"
2930
cc = { version = "1.0", features = ["parallel"] }
3031
pkg-config = "0.3"
3132

33+
[features]
34+
provenance = ["chrono"]
35+
36+
[package.metadata.docs.rs]
37+
all-features = true
38+
3239
[[example]]
3340
name = "mutation_metadata_bincode"
3441

src/_macros.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,35 @@ macro_rules! unsafe_tsk_ragged_column_access {
6363
}};
6464
}
6565

66+
// Allow this to be unused for default features
67+
// to pass clippy checks
68+
#[allow(unused_macros)]
69+
macro_rules! unsafe_tsk_ragged_char_column_access {
70+
($i: expr, $lo: expr, $hi: expr, $array: expr, $offset_array: expr, $offset_array_len: expr) => {{
71+
if $i < $lo || $i >= ($hi as tsk_id_t) {
72+
Err(TskitError::IndexError {})
73+
} else if $offset_array_len == 0 {
74+
Ok(None)
75+
} else {
76+
let start = unsafe { *$offset_array.offset($i as isize) };
77+
let stop = if $i < ($hi as tsk_id_t) {
78+
unsafe { *$offset_array.offset(($i + 1) as isize) }
79+
} else {
80+
$offset_array_len as tsk_size_t
81+
};
82+
if start == stop {
83+
Ok(None)
84+
} else {
85+
let mut buffer = String::new();
86+
for i in start..stop {
87+
buffer.push(unsafe { *$array.offset(i as isize) as u8 as char });
88+
}
89+
Ok(Some(buffer))
90+
}
91+
}
92+
}};
93+
}
94+
6695
macro_rules! drop_for_tskit_type {
6796
($name: ident, $drop: ident) => {
6897
impl Drop for $name {

src/lib.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
//!
1111
//! * [`TableCollection`] wraps `tsk_table_collection_t`.
1212
//! * [`TreeSequence`] wraps `tsk_treeseq_t`.
13-
//! * [`Tree`] wraps `tsk_tree_t`.
13+
//! * [`Tree`] wraps `tsk_tree_t`.
1414
//! * Tree iteration occurs via traits from [streaming_iterator](https://docs.rs/streaming-iterator/).
15-
//! * Errors returned from C map to [`TskitError::ErrorCode`].
15+
//! * Errors returned from C map to [`TskitError::ErrorCode`].
1616
//! Their string messages can be obtained by printing the error type.
1717
//!
1818
//! ## Safety
@@ -24,10 +24,23 @@
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+
//! # Optional features
28+
//!
29+
//! Some features are optional, and are activated by requesting them in your `Cargo.toml` file.
30+
//!
31+
//! * `provenance`
32+
//! * Enables [`provenance`]
33+
//!
34+
//! To add features to your `Cargo.toml` file:
35+
//!
36+
//! ```toml
37+
//! [dependencies]
38+
//! tskit = {version = "0.2.0", features=["feature0", "feature1"]}
39+
//! ```
40+
//!
2741
//! # What is missing?
2842
//!
2943
//! * A lot of wrappers to the C functions.
30-
//! * Support for provenance tables.
3144
//! * Tree sequence statistics!
3245
3346
#![allow(non_upper_case_globals)]
@@ -86,6 +99,10 @@ pub use traits::TableAccess;
8699
pub use traits::TskitTypeAccess;
87100
pub use trees::{NodeTraversalOrder, Tree, TreeSequence};
88101

102+
// Optional features
103+
#[cfg(any(doc, feature = "provenance"))]
104+
pub mod provenance;
105+
89106
/// Handles return codes from low-level tskit functions.
90107
///
91108
/// When an error from the tskit C API is detected,

0 commit comments

Comments
 (0)