Merge rust-bitcoin/rust-bitcoin#2264: Improve the `io` crate
b58c235733
io: Make crate MSRV 1.56.1 (Tobin C. Harding)063dac03bd
Import core::cmp (Tobin C. Harding)c038d00bd1
io: Move use statement (Tobin C. Harding)21c44df76e
inline sink function (Tobin C. Harding)5610b9a6b6
Remove unnecessary rustdoc (Tobin C. Harding) Pull request description: In preparation for adding the `BufRead` trait do a few improvements, the first ones are all trivial, the last sets the MSRV to Rust 1.56.1 ACKs for top commit: Kixunil: ACKb58c235733
apoelstra: ACKb58c235733
Tree-SHA512: e750cd615d9423f4a581b80acb8c928d537538703e2079d7bb700e6155eee4bd9b768c1eb53b0b2aa841497474460ec5926ac59c11eea1722f028efacc87c813
This commit is contained in:
commit
8afa379f39
|
@ -9,7 +9,8 @@ description = "Simple I/O traits for no-std (and std) environments"
|
|||
categories = ["no-std"]
|
||||
keywords = [ "io", "no-std" ]
|
||||
readme = "README.md"
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
rust-version = "1.56.1"
|
||||
exclude = ["tests", "contrib"]
|
||||
|
||||
[features]
|
||||
|
|
|
@ -23,13 +23,12 @@ extern crate alloc;
|
|||
mod error;
|
||||
mod macros;
|
||||
|
||||
use core::convert::TryInto;
|
||||
use core::cmp;
|
||||
|
||||
#[rustfmt::skip] // Keep public re-exports separate.
|
||||
pub use self::error::{Error, ErrorKind};
|
||||
|
||||
/// Standard I/O stream definitions which are API-equivalent to `std`'s `io` module. See
|
||||
/// [`std::io`] for more info.
|
||||
use core::convert::TryInto;
|
||||
|
||||
pub type Result<T> = core::result::Result<T, Error>;
|
||||
|
||||
/// A generic trait describing an input stream. See [`std::io::Read`] for more info.
|
||||
|
@ -61,7 +60,7 @@ pub struct Take<'a, R: Read + ?Sized> {
|
|||
impl<'a, R: Read + ?Sized> Read for Take<'a, R> {
|
||||
#[inline]
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
let len = core::cmp::min(buf.len(), self.remaining.try_into().unwrap_or(buf.len()));
|
||||
let len = cmp::min(buf.len(), self.remaining.try_into().unwrap_or(buf.len()));
|
||||
let read = self.reader.read(&mut buf[..len])?;
|
||||
self.remaining -= read.try_into().unwrap_or(self.remaining);
|
||||
Ok(read)
|
||||
|
@ -80,7 +79,7 @@ impl<R: std::io::Read> Read for R {
|
|||
impl Read for &[u8] {
|
||||
#[inline]
|
||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||
let cnt = core::cmp::min(self.len(), buf.len());
|
||||
let cnt = cmp::min(self.len(), buf.len());
|
||||
buf[..cnt].copy_from_slice(&self[..cnt]);
|
||||
*self = &self[cnt..];
|
||||
Ok(cnt)
|
||||
|
@ -201,4 +200,5 @@ impl std::io::Write for Sink {
|
|||
}
|
||||
|
||||
/// Returns a sink to which all writes succeed. See [`std::io::sink`] for more info.
|
||||
#[inline]
|
||||
pub fn sink() -> Sink { Sink }
|
||||
|
|
Loading…
Reference in New Issue