From: Arik Sosman Date: Thu, 18 Jul 2024 08:46:23 +0000 (-0700) Subject: use canonical io_extras X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ee8579cfc7ad630a7029cfaa4182282f30ab0e15;p=rust-lightning use canonical io_extras --- diff --git a/lightning/src/lib.rs b/lightning/src/lib.rs index 4e835120a..7616346eb 100644 --- a/lightning/src/lib.rs +++ b/lightning/src/lib.rs @@ -96,42 +96,22 @@ pub mod io { #[cfg(feature = "std")] pub use std::io::SeekFrom; } -#[cfg(feature = "std")] -/// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag. -// pub use bitcoin::io; -#[cfg(not(feature = "std"))] -/// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag. -// pub use bitcoin::io; - -#[cfg(not(feature = "std"))] +// #[cfg(feature = "std")] +// /// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag. +// // pub use bitcoin::io; +// #[cfg(not(feature = "std"))] +// /// Re-export of either `core2::io` or `std::io`, depending on the `std` feature flag. +// // pub use bitcoin::io; + #[doc(hidden)] /// IO utilities public only for use by in-crate macros. These should not be used externally /// /// This is not exported to bindings users as it is not intended for public consumption. pub mod io_extras { - use core2::io::{self, Read, Write}; - - /// A writer which will move data into the void. - pub struct Sink { - _priv: (), - } + use bitcoin::io::{self, Read, Write}; /// Creates an instance of a writer which will successfully consume all data. - pub const fn sink() -> Sink { - Sink { _priv: () } - } - - impl core2::io::Write for Sink { - #[inline] - fn write(&mut self, buf: &[u8]) -> core2::io::Result { - Ok(buf.len()) - } - - #[inline] - fn flush(&mut self) -> core2::io::Result<()> { - Ok(()) - } - } + pub use bitcoin::io::sink; pub fn copy(reader: &mut R, writer: &mut W) -> Result where @@ -152,7 +132,7 @@ pub mod io_extras { Ok(count) } - pub fn read_to_end(mut d: D) -> Result, io::Error> { + pub fn read_to_end(mut d: D) -> Result, io::Error> { let mut result = vec![]; let mut buf = [0u8; 64]; loop { @@ -167,21 +147,21 @@ pub mod io_extras { } } -#[cfg(feature = "std")] -#[doc(hidden)] -/// IO utilities public only for use by in-crate macros. These should not be used externally -/// -/// This is not exported to bindings users as it is not intended for public consumption. -mod io_extras { - pub fn read_to_end(mut d: D) -> Result, ::std::io::Error> { - let mut buf = Vec::new(); - d.read_to_end(&mut buf)?; - Ok(buf) - } - - pub use bitcoin::io::sink; - pub use std::io::copy; -} +// #[cfg(feature = "std")] +// #[doc(hidden)] +// /// IO utilities public only for use by in-crate macros. These should not be used externally +// /// +// /// This is not exported to bindings users as it is not intended for public consumption. +// mod io_extras { +// pub fn read_to_end(mut d: D) -> Result, ::std::io::Error> { +// let mut buf = Vec::new(); +// d.read_to_end(&mut buf)?; +// Ok(buf) +// } +// +// pub use bitcoin::io::sink; +// pub use std::io::copy; +// } mod prelude { #![allow(unused_imports)] diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index c93cec3db..ec9022ca4 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -153,24 +153,6 @@ impl<'a, R: Read> Read for FixedLengthReader<'a, R> { } } -impl<'a, R: Read> Read for &mut FixedLengthReader<'a, R> { - #[inline] - fn read(&mut self, dest: &mut [u8]) -> Result { - if self.total_bytes == self.bytes_read { - Ok(0) - } else { - let read_len = cmp::min(dest.len() as u64, self.total_bytes - self.bytes_read); - match self.read.read(&mut dest[0..(read_len as usize)]) { - Ok(v) => { - self.bytes_read += v as u64; - Ok(v) - }, - Err(e) => Err(e), - } - } - } -} - impl<'a, R: Read> LengthRead for FixedLengthReader<'a, R> { #[inline] fn total_bytes(&self) -> u64 {