Fix buggy cfg in rustdocs

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).
This commit is contained in:
Tobin C. Harding 2024-09-26 09:44:18 +10:00
parent 7379eba587
commit 8bb0d3f667
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
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)]