channels_io/impls/
std.rs

1use super::prelude::*;
2
3use ::std::io::ErrorKind as E;
4
5impl IoError for ::std::io::Error {
6	fn should_retry(&self) -> bool {
7		self.kind() == E::Interrupted
8	}
9}
10
11impl ReadError for ::std::io::Error {
12	fn eof() -> Self {
13		Self::from(E::UnexpectedEof)
14	}
15}
16
17impl WriteError for ::std::io::Error {
18	fn write_zero() -> Self {
19		Self::from(E::WriteZero)
20	}
21}
22
23/// Wrapper IO type for [`std::io::Read`] and [`std::io::Write`].
24#[derive(Debug)]
25pub struct Std<T>(pub T);
26
27impl_newtype! { Std }
28
29impl_newtype_read! { Std: ::std::io::Read }
30
31impl<T> Read for Std<T>
32where
33	T: ::std::io::Read,
34{
35	type Error = ::std::io::Error;
36
37	fn read_slice(
38		&mut self,
39		buf: &mut [u8],
40	) -> Result<usize, Self::Error> {
41		self.0.read(buf)
42	}
43}
44
45impl_newtype_write! { Std: ::std::io::Write }
46
47impl<T> Write for Std<T>
48where
49	T: ::std::io::Write,
50{
51	type Error = ::std::io::Error;
52
53	fn write_slice(
54		&mut self,
55		buf: &[u8],
56	) -> Result<usize, Self::Error> {
57		self.0.write(buf)
58	}
59
60	fn flush_once(&mut self) -> Result<(), Self::Error> {
61		self.0.flush()
62	}
63}