diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs index 65984cbf..8d1980dc 100644 --- a/bitcoin/src/lib.rs +++ b/bitcoin/src/lib.rs @@ -189,7 +189,7 @@ mod prelude { pub use std::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap}; #[cfg(feature = "std")] - pub use std::io::sink; + pub use crate::io::sink; #[cfg(not(feature = "std"))] pub use crate::io_extras::sink; diff --git a/io/src/lib.rs b/io/src/lib.rs index 93d09795..ee531fc4 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -36,7 +36,7 @@ pub mod io { compile_error!("At least one of std or core2 must be enabled"); #[cfg(feature = "std")] - pub use std::io::{Read, sink, Cursor, Take, Error, ErrorKind, Result}; + pub use std::io::{Read, Cursor, Take, Error, ErrorKind, Result}; #[cfg(not(feature = "std"))] pub use core2::io::{Read, Cursor, Take, Error, ErrorKind, Result}; @@ -95,6 +95,33 @@ pub mod io { #[inline] fn flush(&mut self) -> Result<()> { Ok(()) } } + + /// A sink to which all writes succeed. See [`std::io::Sink`] for more info. + pub struct Sink; + #[cfg(not(feature = "std"))] + impl Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> Result { + Ok(buf.len()) + } + #[inline] + fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) } + #[inline] + fn flush(&mut self) -> Result<()> { Ok(()) } + } + #[cfg(feature = "std")] + impl std::io::Write for Sink { + #[inline] + fn write(&mut self, buf: &[u8]) -> std::io::Result { + Ok(buf.len()) + } + #[inline] + fn write_all(&mut self, _: &[u8]) -> std::io::Result<()> { Ok(()) } + #[inline] + fn flush(&mut self) -> std::io::Result<()> { Ok(()) } + } + /// Returns a sink to which all writes succeed. See [`std::io::sink`] for more info. + pub fn sink() -> Sink { Sink } } #[doc(hidden)]