Skip to content

Commit 734c23b

Browse files
committed
bug: add feature gates for rand
Fails to build without the feature gate `#[cfg(feature = "rand")]` since rand is optional. Where ever the feature gate is used, also add `#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]` which is used by docs.rs. Should ensure that the attribute is active when docs.rs is generating the documentation. Also, remove `default-features = false` from the optional rand dependence since `std` is a required feature of rand by this project.
1 parent 8a21be2 commit 734c23b

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ features = ["rand"]
1818

1919
[dependencies]
2020
bitcoin = "0.32.7"
21-
rand = { version = "0.8.5", default-features = false, optional = true }
21+
rand = { version = "0.8.5", optional = true }
2222

2323
[dev-dependencies]
2424
bitcoin = "0.32.7"

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ mod branch_and_bound;
1515
mod single_random_draw;
1616

1717
use bitcoin::{Amount, FeeRate, SignedAmount, Weight};
18+
#[cfg(feature = "rand")]
19+
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
1820
use rand::thread_rng;
1921

2022
pub use crate::branch_and_bound::select_coins_bnb;
23+
#[cfg(feature = "rand")]
24+
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
2125
pub use crate::single_random_draw::select_coins_srd;
2226

2327
pub(crate) type Return<'a, Utxo> = Option<(u32, Vec<&'a Utxo>)>;

src/single_random_draw.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
77
use bitcoin::blockdata::transaction::effective_value;
88
use bitcoin::{Amount, FeeRate};
9+
#[cfg(feature = "rand")]
10+
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
911
use rand::seq::SliceRandom;
1012

1113
use crate::{Return, WeightedUtxo, CHANGE_LOWER};
@@ -33,6 +35,8 @@ use crate::{Return, WeightedUtxo, CHANGE_LOWER};
3335
/// - Not enough potential amount to meet the target
3436
/// - Target Amount is zero (no match possible)
3537
/// - Search was successful yet no match found
38+
#[cfg(feature = "rand")]
39+
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
3640
pub fn select_coins_srd<'a, R: rand::Rng + ?Sized, Utxo: WeightedUtxo>(
3741
target: Amount,
3842
fee_rate: FeeRate,

0 commit comments

Comments
 (0)