From 280eb2239a2fcaa83a35ae6fb1ce62fe35a1e222 Mon Sep 17 00:00:00 2001 From: "Tobin C. Harding" Date: Fri, 17 Jan 2025 11:51:20 +1100 Subject: [PATCH] io: Remove the impl_write macro 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. Remove the macro. While we are at it point users to the examples in `bitcoin/examples/io.rs` for usage of the `io` crate. --- io/src/lib.rs | 4 +++- io/src/macros.rs | 58 ------------------------------------------------ 2 files changed, 3 insertions(+), 59 deletions(-) delete mode 100644 io/src/macros.rs diff --git a/io/src/lib.rs b/io/src/lib.rs index 0e1d33126..71e71bb7e 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -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. @@ -28,7 +31,6 @@ extern crate alloc; #[cfg(feature = "std")] mod bridge; mod error; -mod macros; #[cfg(all(not(feature = "std"), feature = "alloc"))] use alloc::vec::Vec; diff --git a/io/src/macros.rs b/io/src/macros.rs deleted file mode 100644 index 55df18aa7..000000000 --- a/io/src/macros.rs +++ /dev/null @@ -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 { - $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 { - $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 { - $write_fn(self, buf) - } - #[inline] - fn flush(&mut self) -> $crate::Result<()> { - $flush_fn(self) - } - } - } -}