Merge rust-bitcoin/rust-bitcoin#3916: io: Remove the `impl_write` macro

280eb2239a io: Remove the impl_write macro (Tobin C. Harding)

Pull request description:

  We have found calling macros from other crates to be error prone, especially when they involve feature gates. Furthermore the `impl_write` macro is trivial to write, users can just write it in the crate that needs it.

  Lets just remove the macro. While we are at it point users to the examples in `bitcoin/examples/io.rs` for usage of the `io` crate.

  Close: #3872

ACKs for top commit:
  Kixunil:
    ACK 280eb2239a
  apoelstra:
    ACK 280eb2239a2fcaa83a35ae6fb1ce62fe35a1e222; successfully ran local tests

Tree-SHA512: 62766ff6e4b5f3fae2d6214e87bd90c15b3103248effd4399a070ac831473b0288e599eed2377c08d2b7eca263220f172c8399a607756793477f82d3dc8f1b67
This commit is contained in:
merge-script 2025-03-26 13:49:58 +00:00
commit 4dd86ad40b
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 3 additions and 59 deletions

View File

@ -9,6 +9,9 @@
//!
//! These traits are not one-for-one drop-ins, but are as close as possible while still implementing
//! `std::io`'s traits without unnecessary complexity.
//!
//! For examples of how to use and implement the types and traits in this crate see `io.rs` in the
//! `github.com/rust-bitcoin/rust-bitcoin/bitcoin/examples/` directory.
#![cfg_attr(not(feature = "std"), no_std)]
// Experimental features we need.
@ -31,7 +34,6 @@ pub extern crate hashes;
#[cfg(feature = "std")]
mod bridge;
mod error;
mod macros;
#[cfg(feature = "hashes")]
mod hash;

View File

@ -1,58 +0,0 @@
// SPDX-License-Identifier: CC0-1.0
/// Implements [`crate::Write`] for `$ty`.
// See below for docs (docs.rs build enables all features).
#[cfg(not(feature = "std"))]
#[macro_export]
macro_rules! impl_write {
($ty: ty, $write_fn: expr, $flush_fn: expr $(, $bounded_ty: ident : $bounds: path),*) => {
impl<$($bounded_ty: $bounds),*> $crate::Write for $ty {
#[inline]
fn write(&mut self, buf: &[u8]) -> $crate::Result<usize> {
$write_fn(self, buf)
}
#[inline]
fn flush(&mut self) -> $crate::Result<()> {
$flush_fn(self)
}
}
}
}
/// Implements [`crate::Write`] for `$ty`.
///
/// Also implements [`std::io::Write`] for `$ty` if `bitcoin_io` has the `std` feature enabled.
///
/// # Arguments
///
/// * `$ty` - the type used to implement the two traits.
/// * `write_fn` - the function called by the `Write::write` trait method.
/// * `flush_fn` - the function called by the `Write::flush` trait method.
/// * `$bounded_ty: $bounds` - optional trait bounds if required.
#[cfg(feature = "std")]
#[macro_export]
macro_rules! impl_write {
($ty: ty, $write_fn: expr, $flush_fn: expr $(, $bounded_ty: ident : $bounds: path),*) => {
impl<$($bounded_ty: $bounds),*> std::io::Write for $ty {
#[inline]
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
$write_fn(self, buf)
}
#[inline]
fn flush(&mut self) -> std::io::Result<()> {
$flush_fn(self)
}
}
impl<$($bounded_ty: $bounds),*> $crate::Write for $ty {
#[inline]
fn write(&mut self, buf: &[u8]) -> $crate::Result<usize> {
$write_fn(self, buf)
}
#[inline]
fn flush(&mut self) -> $crate::Result<()> {
$flush_fn(self)
}
}
}
}