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.
This commit is contained in:
parent
786e835312
commit
280eb2239a
|
@ -9,6 +9,9 @@
|
||||||
//!
|
//!
|
||||||
//! These traits are not one-for-one drop-ins, but are as close as possible while still implementing
|
//! 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.
|
//! `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)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
// Experimental features we need.
|
// Experimental features we need.
|
||||||
|
@ -28,7 +31,6 @@ extern crate alloc;
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
mod bridge;
|
mod bridge;
|
||||||
mod error;
|
mod error;
|
||||||
mod macros;
|
|
||||||
|
|
||||||
#[cfg(all(not(feature = "std"), feature = "alloc"))]
|
#[cfg(all(not(feature = "std"), feature = "alloc"))]
|
||||||
use alloc::vec::Vec;
|
use alloc::vec::Vec;
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue