[IO] Replace `std::io::Sink` usage with our own trivial impl
This commit is contained in:
parent
7eb5d65bda
commit
6aa7ccf841
|
@ -189,7 +189,7 @@ mod prelude {
|
||||||
pub use std::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
|
pub use std::collections::{BTreeMap, BTreeSet, btree_map, BinaryHeap};
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub use std::io::sink;
|
pub use crate::io::sink;
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
pub use crate::io_extras::sink;
|
pub use crate::io_extras::sink;
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub mod io {
|
||||||
compile_error!("At least one of std or core2 must be enabled");
|
compile_error!("At least one of std or core2 must be enabled");
|
||||||
|
|
||||||
#[cfg(feature = "std")]
|
#[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"))]
|
#[cfg(not(feature = "std"))]
|
||||||
pub use core2::io::{Read, Cursor, Take, Error, ErrorKind, Result};
|
pub use core2::io::{Read, Cursor, Take, Error, ErrorKind, Result};
|
||||||
|
@ -95,6 +95,33 @@ pub mod io {
|
||||||
#[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.
|
||||||
|
pub struct Sink;
|
||||||
|
#[cfg(not(feature = "std"))]
|
||||||
|
impl Write for Sink {
|
||||||
|
#[inline]
|
||||||
|
fn write(&mut self, buf: &[u8]) -> Result<usize> {
|
||||||
|
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<usize> {
|
||||||
|
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)]
|
#[doc(hidden)]
|
||||||
|
|
Loading…
Reference in New Issue