channels_io/impls/
core2.rs

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