Use rand-std in key rustdoc examples

Seems there is a bug in cargo, the tests in `key.rs` run successfully
but AFAICT they should fail. Here is an example, running `cargo test
--features=rand` should make this test fail but it doesn't?
```
/// Secret 256-bit key used as `x` in an ECDSA signature.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// # #[cfg(all(feature = "rand", any(feature =  "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey};
///
/// let secp = Secp256k1::new();
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// # }
/// ```

Anywho, use the correct feature gate: `rand-std`.
This commit is contained in:
Tobin Harding 2022-02-01 14:00:10 +11:00
parent ae3e06f95b
commit f3688ecf56
1 changed files with 13 additions and 13 deletions

View File

@ -35,7 +35,7 @@ use ffi::{self, CPtr};
/// Basic usage: /// Basic usage:
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey}; /// use secp256k1::{rand, Secp256k1, SecretKey};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -129,7 +129,7 @@ impl SecretKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(feature="rand")] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, SecretKey}; /// use secp256k1::{rand, SecretKey};
/// let secret_key = SecretKey::new(&mut rand::thread_rng()); /// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// # } /// # }
@ -185,7 +185,7 @@ impl SecretKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair}; /// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -329,7 +329,7 @@ impl PublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey}; /// use secp256k1::{rand, Secp256k1, SecretKey, PublicKey};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -377,7 +377,7 @@ impl PublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, PublicKey, KeyPair}; /// use secp256k1::{rand, Secp256k1, PublicKey, KeyPair};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -508,7 +508,7 @@ impl PublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1}; /// use secp256k1::{rand, Secp256k1};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -534,7 +534,7 @@ impl PublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, PublicKey}; /// use secp256k1::{rand, Secp256k1, PublicKey};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -650,7 +650,7 @@ impl Ord for PublicKey {
/// Basic usage: /// Basic usage:
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, KeyPair, Secp256k1}; /// use secp256k1::{rand, KeyPair, Secp256k1};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -744,7 +744,7 @@ impl KeyPair {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair}; /// use secp256k1::{rand, Secp256k1, SecretKey, KeyPair};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -790,7 +790,7 @@ impl KeyPair {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{Secp256k1, KeyPair}; /// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{RngCore, thread_rng}; /// use secp256k1::rand::{RngCore, thread_rng};
/// ///
@ -914,7 +914,7 @@ impl<'de> ::serde::Deserialize<'de> for KeyPair {
/// Basic usage: /// Basic usage:
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{rand, Secp256k1, KeyPair, XOnlyPublicKey}; /// use secp256k1::{rand, Secp256k1, KeyPair, XOnlyPublicKey};
/// ///
/// let secp = Secp256k1::new(); /// let secp = Secp256k1::new();
@ -1042,7 +1042,7 @@ impl XOnlyPublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{Secp256k1, KeyPair}; /// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{RngCore, thread_rng}; /// use secp256k1::rand::{RngCore, thread_rng};
/// ///
@ -1107,7 +1107,7 @@ impl XOnlyPublicKey {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # #[cfg(all(feature = "rand", any(feature = "alloc", feature = "std")))] { /// # #[cfg(all(feature = "rand-std", any(feature = "alloc", feature = "std")))] {
/// use secp256k1::{Secp256k1, KeyPair}; /// use secp256k1::{Secp256k1, KeyPair};
/// use secp256k1::rand::{thread_rng, RngCore}; /// use secp256k1::rand::{thread_rng, RngCore};
/// ///