Add vertical whitespace
Make the `io` crate conform to `rust-bitcoin` code style in regards to whitespace between functions/types etc. Whitespace only, no other changes.
This commit is contained in:
parent
3ddf60ffd4
commit
f83d68f246
|
@ -34,12 +34,15 @@ mod sealed {
|
||||||
use alloc::boxed::Box;
|
use alloc::boxed::Box;
|
||||||
use alloc::string::String;
|
use alloc::string::String;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
|
|
||||||
pub trait IntoBoxDynDebug {
|
pub trait IntoBoxDynDebug {
|
||||||
fn into(self) -> Box<dyn Debug + Send + Sync + 'static>;
|
fn into(self) -> Box<dyn Debug + Send + Sync + 'static>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoBoxDynDebug for &str {
|
impl IntoBoxDynDebug for &str {
|
||||||
fn into(self) -> Box<dyn Debug + Send + Sync + 'static> { Box::new(String::from(self)) }
|
fn into(self) -> Box<dyn Debug + Send + Sync + 'static> { Box::new(String::from(self)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoBoxDynDebug for String {
|
impl IntoBoxDynDebug for String {
|
||||||
fn into(self) -> Box<dyn Debug + Send + Sync + 'static> { Box::new(self) }
|
fn into(self) -> Box<dyn Debug + Send + Sync + 'static> { Box::new(self) }
|
||||||
}
|
}
|
||||||
|
@ -54,6 +57,7 @@ pub struct Error {
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
error: Option<Box<dyn Debug + Send + Sync + 'static>>,
|
error: Option<Box<dyn Debug + Send + Sync + 'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn new<E>(kind: ErrorKind, error: E) -> Error
|
pub fn new<E>(kind: ErrorKind, error: E) -> Error
|
||||||
|
@ -62,6 +66,7 @@ impl Error {
|
||||||
{
|
{
|
||||||
Self { kind, error: Some(error.into()) }
|
Self { kind, error: Some(error.into()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
pub fn new<E: sealed::IntoBoxDynDebug>(kind: ErrorKind, error: E) -> Error {
|
pub fn new<E: sealed::IntoBoxDynDebug>(kind: ErrorKind, error: E) -> Error {
|
||||||
Self { kind, error: Some(error.into()) }
|
Self { kind, error: Some(error.into()) }
|
||||||
|
@ -96,6 +101,7 @@ impl std::error::Error for Error {
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||||
self.error.as_ref().and_then(|e| e.as_ref().source())
|
self.error.as_ref().and_then(|e| e.as_ref().source())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
match self.error.as_ref() {
|
match self.error.as_ref() {
|
||||||
|
@ -103,6 +109,7 @@ impl std::error::Error for Error {
|
||||||
None => self.kind.description(),
|
None => self.kind.description(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
fn cause(&self) -> Option<&dyn std::error::Error> {
|
fn cause(&self) -> Option<&dyn std::error::Error> {
|
||||||
self.error.as_ref().and_then(|e| e.as_ref().cause())
|
self.error.as_ref().and_then(|e| e.as_ref().cause())
|
||||||
|
@ -114,6 +121,7 @@ impl Error {
|
||||||
pub fn get_ref(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> {
|
pub fn get_ref(&self) -> Option<&(dyn std::error::Error + Send + Sync + 'static)> {
|
||||||
self.error.as_deref()
|
self.error.as_deref()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||||
pub fn get_ref(&self) -> Option<&(dyn Debug + Send + Sync + 'static)> { self.error.as_deref() }
|
pub fn get_ref(&self) -> Option<&(dyn Debug + Send + Sync + 'static)> { self.error.as_deref() }
|
||||||
}
|
}
|
||||||
|
@ -154,12 +162,14 @@ macro_rules! define_errorkind {
|
||||||
$(Self::$kind => stringify!($kind)),*
|
$(Self::$kind => stringify!($kind)),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn to_std(self) -> std::io::ErrorKind {
|
fn to_std(self) -> std::io::ErrorKind {
|
||||||
match self {
|
match self {
|
||||||
$(Self::$kind => std::io::ErrorKind::$kind),*
|
$(Self::$kind => std::io::ErrorKind::$kind),*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
fn from_std(o: std::io::ErrorKind) -> ErrorKind {
|
fn from_std(o: std::io::ErrorKind) -> ErrorKind {
|
||||||
match o {
|
match o {
|
||||||
|
@ -198,6 +208,7 @@ pub type Result<T> = core::result::Result<T, Error>;
|
||||||
/// A generic trait describing an input stream. See [`std::io::Read`] for more info.
|
/// A generic trait describing an input stream. See [`std::io::Read`] for more info.
|
||||||
pub trait Read {
|
pub trait Read {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
|
fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<()> {
|
||||||
while !buf.is_empty() {
|
while !buf.is_empty() {
|
||||||
|
@ -210,6 +221,7 @@ pub trait Read {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn take(&mut self, limit: u64) -> Take<Self> { Take { reader: self, remaining: limit } }
|
fn take(&mut self, limit: u64) -> Take<Self> { Take { reader: self, remaining: limit } }
|
||||||
}
|
}
|
||||||
|
@ -218,6 +230,7 @@ pub struct Take<'a, R: Read + ?Sized> {
|
||||||
reader: &'a mut R,
|
reader: &'a mut R,
|
||||||
remaining: u64,
|
remaining: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, R: Read + ?Sized> Read for Take<'a, R> {
|
impl<'a, R: Read + ?Sized> Read for Take<'a, R> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||||
|
@ -251,14 +264,18 @@ pub struct Cursor<T> {
|
||||||
inner: T,
|
inner: T,
|
||||||
pos: u64,
|
pos: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<[u8]>> Cursor<T> {
|
impl<T: AsRef<[u8]>> Cursor<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new(inner: T) -> Self { Cursor { inner, pos: 0 } }
|
pub fn new(inner: T) -> Self { Cursor { inner, pos: 0 } }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn position(&self) -> u64 { self.pos }
|
pub fn position(&self) -> u64 { self.pos }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_inner(self) -> T { self.inner }
|
pub fn into_inner(self) -> T { self.inner }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
|
||||||
|
@ -275,6 +292,7 @@ impl<T: AsRef<[u8]>> Read for Cursor<T> {
|
||||||
/// A generic trait describing an output stream. See [`std::io::Write`] for more info.
|
/// A generic trait describing an output stream. See [`std::io::Write`] for more info.
|
||||||
pub trait Write {
|
pub trait Write {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize>;
|
fn write(&mut self, buf: &[u8]) -> Result<usize>;
|
||||||
|
|
||||||
fn flush(&mut self) -> Result<()>;
|
fn flush(&mut self) -> Result<()>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -297,6 +315,7 @@ impl<W: std::io::Write> Write for W {
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||||
Ok(<W as std::io::Write>::write(self, buf)?)
|
Ok(<W as std::io::Write>::write(self, buf)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<()> { Ok(<W as std::io::Write>::flush(self)?) }
|
fn flush(&mut self) -> Result<()> { Ok(<W as std::io::Write>::flush(self)?) }
|
||||||
}
|
}
|
||||||
|
@ -308,6 +327,7 @@ impl Write for alloc::vec::Vec<u8> {
|
||||||
self.extend_from_slice(buf);
|
self.extend_from_slice(buf);
|
||||||
Ok(buf.len())
|
Ok(buf.len())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<()> { Ok(()) }
|
fn flush(&mut self) -> Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
@ -321,29 +341,37 @@ impl<'a> Write for &'a mut [u8] {
|
||||||
*self = &mut core::mem::take(self)[cnt..];
|
*self = &mut core::mem::take(self)[cnt..];
|
||||||
Ok(cnt)
|
Ok(cnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<()> { Ok(()) }
|
fn flush(&mut self) -> Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A sink to which all writes succeed. See [`std::io::Sink`] for more info.
|
/// A sink to which all writes succeed. See [`std::io::Sink`] for more info.
|
||||||
pub struct Sink;
|
pub struct Sink;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
impl Write for Sink {
|
impl Write for Sink {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
|
fn write(&mut self, buf: &[u8]) -> Result<usize> { Ok(buf.len()) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
|
fn write_all(&mut self, _: &[u8]) -> Result<()> { Ok(()) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> Result<()> { Ok(()) }
|
fn flush(&mut self) -> Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
impl std::io::Write for Sink {
|
impl std::io::Write for Sink {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { Ok(buf.len()) }
|
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { Ok(buf.len()) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_all(&mut self, _: &[u8]) -> std::io::Result<()> { Ok(()) }
|
fn write_all(&mut self, _: &[u8]) -> std::io::Result<()> { Ok(()) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn flush(&mut self) -> std::io::Result<()> { Ok(()) }
|
fn flush(&mut self) -> std::io::Result<()> { Ok(()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a sink to which all writes succeed. See [`std::io::sink`] for more info.
|
/// Returns a sink to which all writes succeed. See [`std::io::sink`] for more info.
|
||||||
pub fn sink() -> Sink { Sink }
|
pub fn sink() -> Sink { Sink }
|
||||||
|
|
Loading…
Reference in New Issue