Merge rust-bitcoin/rust-bitcoin#3410: Fix buggy cfg in rustdocs

8bb0d3f667 Fix buggy cfg in rustdocs (Tobin C. Harding)

Pull request description:

  In b9643bf3e9 we introduced an incorrect `cfg` attribute, that has just shown up, no clue why clippy only just presented me with this error now. Anywho, the current code is buggy and the rustdoc tests are never being run.

  Fix `cfg` attribute to use the feature name correctly and fix the imports so the code runs.

  Maintain the explicit `main` so that we can return an error using the `?` operator. Remove the empty `main` because its not needed anymore, it is a hang-over from Rust back in the day (before main was automatically added, IIUC).

ACKs for top commit:
  apoelstra:
    ACK 8bb0d3f667 successfully ran local tests

Tree-SHA512: 27f571ac3644417c06d0b4eb6fb122b39ac1068aefa4bcfc03f1febe2d031fb30616883c55c42c2ec80d419572fe7eba9bcc239e3c0e0e178ec7eaf8533b9efe
This commit is contained in:
merge-script 2024-10-01 14:37:29 +00:00
commit de120de5b9
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
1 changed files with 17 additions and 24 deletions

View File

@ -11,7 +11,7 @@
//! //!
//! Hashing a single byte slice or a string: //! Hashing a single byte slice or a string:
//! //!
//! ```rust //! ```
//! use bitcoin_hashes::Sha256; //! use bitcoin_hashes::Sha256;
//! //!
//! let bytes = [0u8; 5]; //! let bytes = [0u8; 5];
@ -22,39 +22,32 @@
//! //!
//! Hashing content from a reader: //! Hashing content from a reader:
//! //!
//! ```rust //! ```
//! #[cfg(std)] //! #[cfg(feature = "std")] {
//! # fn main() -> std::io::Result<()> { //! use bitcoin_hashes::Sha256;
//! let mut reader: &[u8] = b"hello"; // in real code, this could be a `File` or `TcpStream` //! let mut reader: &[u8] = b"hello"; // in real code, this could be a `File` or `TcpStream`
//! let mut engine = Sha256::engine(); //! let mut engine = Sha256::engine();
//! std::io::copy(&mut reader, &mut engine)?; //! std::io::copy(&mut reader, &mut engine).unwrap();
//! let hash = Sha256::from_engine(engine); //! let _hash = Sha256::from_engine(engine);
//! # Ok(())
//! # } //! # }
//!
//! #[cfg(not(std))]
//! # fn main() {}
//! ``` //! ```
//! //!
//! //!
//! Hashing content by [`std::io::Write`] on `HashEngine`: //! Hashing content by [`std::io::Write`] on `HashEngine`:
//! //!
//! ```rust //! ```
//! #[cfg(std)] //! #[cfg(feature = "std")] {
//! # fn main() -> std::io::Result<()> { //! use std::io::Write as _; // Or `bitcoin-io::Write` if `bitcoin-io` feature is enabled.
//! let mut part1: &[u8] = b"hello"; //! use bitcoin_hashes::Sha256;
//! let mut part2: &[u8] = b" "; //! let part1: &[u8] = b"hello";
//! let mut part3: &[u8] = b"world"; //! let part2: &[u8] = b" ";
//! let part3: &[u8] = b"world";
//! let mut engine = Sha256::engine(); //! let mut engine = Sha256::engine();
//! engine.write_all(part1)?; //! engine.write_all(part1).expect("engine writes don't error");
//! engine.write_all(part2)?; //! engine.write_all(part2).unwrap();
//! engine.write_all(part3)?; //! engine.write_all(part3).unwrap();
//! let hash = Sha256::from_engine(engine); //! let _hash = Sha256::from_engine(engine);
//! # Ok(())
//! # } //! # }
//!
//! #[cfg(not(std))]
//! # fn main() {}
//! ``` //! ```
#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(not(feature = "std"), no_std)]