#![allow(missing_copy_implementations)]
use crate::fmt;
-use crate::io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoSlice, IoSliceMut};
+use crate::io::{self, BufRead, ErrorKind, Initializer, IoSlice, IoSliceMut, Read, Write};
use crate::mem::MaybeUninit;
/// Copies the entire contents of a reader into a writer.
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<u64>
- where R: Read, W: Write
+where
+ R: Read,
+ W: Write,
{
let mut buf = MaybeUninit::<[u8; super::DEFAULT_BUF_SIZE]>::uninit();
// FIXME(#53491): This is calling `get_mut` and `get_ref` on an uninitialized
// This is still technically undefined behavior due to creating a reference
// to uninitialized data, but within libstd we can rely on more guarantees
// than if this code were in an external lib.
- unsafe { reader.initializer().initialize(buf.get_mut()); }
+ unsafe {
+ reader.initializer().initialize(buf.get_mut());
+ }
let mut written = 0;
loop {
///
/// [`empty`]: fn.empty.html
#[stable(feature = "rust1", since = "1.0.0")]
-pub struct Empty { _priv: () }
+pub struct Empty {
+ _priv: (),
+}
/// Constructs a new handle to an empty reader.
///
/// assert!(buffer.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
-pub fn empty() -> Empty { Empty { _priv: () } }
+pub fn empty() -> Empty {
+ Empty { _priv: () }
+}
#[stable(feature = "rust1", since = "1.0.0")]
impl Read for Empty {
#[inline]
- fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> { Ok(0) }
+ fn read(&mut self, _buf: &mut [u8]) -> io::Result<usize> {
+ Ok(0)
+ }
#[inline]
unsafe fn initializer(&self) -> Initializer {
#[stable(feature = "rust1", since = "1.0.0")]
impl BufRead for Empty {
#[inline]
- fn fill_buf(&mut self) -> io::Result<&[u8]> { Ok(&[]) }
+ fn fill_buf(&mut self) -> io::Result<&[u8]> {
+ Ok(&[])
+ }
#[inline]
fn consume(&mut self, _n: usize) {}
}
///
/// [repeat]: fn.repeat.html
#[stable(feature = "rust1", since = "1.0.0")]
-pub struct Repeat { byte: u8 }
+pub struct Repeat {
+ byte: u8,
+}
/// Creates an instance of a reader that infinitely repeats one byte.
///
/// assert_eq!(buffer, [0b101, 0b101, 0b101]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
-pub fn repeat(byte: u8) -> Repeat { Repeat { byte } }
+pub fn repeat(byte: u8) -> Repeat {
+ Repeat { byte }
+}
#[stable(feature = "rust1", since = "1.0.0")]
impl Read for Repeat {
///
/// [sink]: fn.sink.html
#[stable(feature = "rust1", since = "1.0.0")]
-pub struct Sink { _priv: () }
+pub struct Sink {
+ _priv: (),
+}
/// Creates an instance of a writer which will successfully consume all data.
///
/// assert_eq!(num_bytes, 5);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
-pub fn sink() -> Sink { Sink { _priv: () } }
+pub fn sink() -> Sink {
+ Sink { _priv: () }
+}
#[stable(feature = "rust1", since = "1.0.0")]
impl Write for Sink {
#[inline]
- fn write(&mut self, buf: &[u8]) -> io::Result<usize> { Ok(buf.len()) }
+ fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
+ Ok(buf.len())
+ }
#[inline]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
}
#[inline]
- fn flush(&mut self) -> io::Result<()> { Ok(()) }
+ fn flush(&mut self) -> io::Result<()> {
+ Ok(())
+ }
}
#[stable(feature = "std_debug", since = "1.16.0")]
#[cfg(test)]
mod tests {
use crate::io::prelude::*;
- use crate::io::{copy, sink, empty, repeat};
+ use crate::io::{copy, empty, repeat, sink};
#[test]
fn copy_copies() {