Skip to content

Commit fc1142a

Browse files
authored
doc: display feture flags in docs.rs (#338)
* pass rustdoc-args on docs.rs * use doc_cfg for provenance
1 parent 84c0cb4 commit fc1142a

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ derive = ["tskit-derive", "serde", "serde_json", "bincode"]
5050

5151
[package.metadata.docs.rs]
5252
all-features = true
53+
rustdoc-args = ["--cfg", "doc_cfg"]
5354

5455
# Not run during tests
5556
[[example]]

src/_macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ macro_rules! migration_table_add_row_with_metadata {
10321032
};
10331033
}
10341034

1035-
#[cfg(any(doc, feature = "provenance"))]
1035+
#[cfg(feature = "provenance")]
1036+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
10361037
macro_rules! provenance_table_add_row {
10371038
($(#[$attr:meta])* => $name: ident, $self: ident, $table: expr) => {
10381039
$(#[$attr])*

src/lib.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//! Some features are optional, and are activated by requesting them in your `Cargo.toml` file.
4545
//!
4646
//! * `provenance`
47-
//! * Enables [`provenance`]
47+
//! * Enables `provenance`
4848
//! * `derive` enables the following derive macros:
4949
//! * [`crate::metadata::MutationMetadata`]
5050
//! * [`crate::metadata::IndividualMetadata`]
@@ -72,6 +72,7 @@
7272
#![allow(non_upper_case_globals)]
7373
#![allow(non_camel_case_types)]
7474
#![allow(non_snake_case)]
75+
#![cfg_attr(doc_cfg, feature(doc_cfg))]
7576

7677
#[allow(deref_nullptr)]
7778
#[allow(rustdoc::broken_intra_doc_links)]
@@ -444,10 +445,12 @@ pub use tree_interface::{NodeTraversalOrder, TreeInterface};
444445
pub use trees::{Tree, TreeSequence};
445446

446447
// Optional features
447-
#[cfg(any(feature = "provenance", doc))]
448+
#[cfg(feature = "provenance")]
449+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
448450
pub mod provenance;
449451

450-
#[cfg(any(feature = "provenance", doc))]
452+
#[cfg(feature = "provenance")]
453+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
451454
/// A provenance ID
452455
///
453456
/// This is an integer referring to a row of a [``provenance::ProvenanceTable``].

src/provenance.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ build_owned_table_type!(
184184
/// # Examples
185185
///
186186
/// ```rust
187-
/// # #[cfg(any(doc, feature = "provenance"))] {
187+
/// # #[cfg(feature = "provenance")]
188+
/// # #[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
189+
/// {
188190
/// use tskit::provenance::OwnedProvenanceTable;
189191
/// let mut provenances = OwnedProvenanceTable::default();
190192
/// let id = provenances.add_row("message").unwrap();

src/table_collection.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,8 @@ impl TableCollection {
848848
handle_tsk_return_value!(rv)
849849
}
850850

851-
#[cfg(any(feature = "provenance", doc))]
851+
#[cfg(feature = "provenance")]
852+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
852853
provenance_table_add_row!(
853854
/// Add provenance record with a time stamp.
854855
///
@@ -1159,7 +1160,8 @@ impl TableCollection {
11591160
handle_tsk_return_value!(rv)
11601161
}
11611162

1162-
#[cfg(any(doc, feature = "provenance"))]
1163+
#[cfg(feature = "provenance")]
1164+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
11631165
/// Set the provenance table from an
11641166
/// [`OwnedProvenanceTable`](`crate::provenance::OwnedProvenanceTable`)
11651167
///
@@ -1231,7 +1233,8 @@ impl TableAccess for TableCollection {
12311233
PopulationTable::new_from_table(&self.inner.populations)
12321234
}
12331235

1234-
#[cfg(any(feature = "provenance", doc))]
1236+
#[cfg(feature = "provenance")]
1237+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
12351238
fn provenances(&self) -> crate::provenance::ProvenanceTable {
12361239
crate::provenance::ProvenanceTable::new_from_table(&self.inner.provenances)
12371240
}

src/traits.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ pub trait TableAccess {
113113
Box::new(make_table_iterator::<IndividualTable>(self.individuals()))
114114
}
115115

116-
#[cfg(any(feature = "provenance", doc))]
116+
#[cfg(feature = "provenance")]
117+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
117118
/// Get reference to the [``ProvenanceTable``](crate::provenance::ProvenanceTable)
118119
fn provenances(&self) -> crate::provenance::ProvenanceTable;
119120

120-
#[cfg(any(feature = "provenance", doc))]
121+
#[cfg(feature = "provenance")]
122+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
121123
/// Return an iterator over provenances
122124
fn provenances_iter(
123125
&self,

src/trees.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ impl TreeSequence {
454454
)
455455
}
456456

457-
#[cfg(any(feature = "provenance", doc))]
457+
#[cfg(feature = "provenance")]
458+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
458459
/// Add provenance record with a time stamp.
459460
///
460461
/// All implementation of this trait provided by `tskit` use
@@ -540,7 +541,8 @@ impl TableAccess for TreeSequence {
540541
PopulationTable::new_from_table(unsafe { &(*self.inner.tables).populations })
541542
}
542543

543-
#[cfg(any(feature = "provenance", doc))]
544+
#[cfg(feature = "provenance")]
545+
#[cfg_attr(doc_cfg, doc(cfg(feature = "provenance")))]
544546
fn provenances(&self) -> crate::provenance::ProvenanceTable {
545547
crate::provenance::ProvenanceTable::new_from_table(unsafe {
546548
&(*self.inner.tables).provenances

0 commit comments

Comments
 (0)