channels_io/impls/
smol.rs1use super::prelude::*;
2
3#[cfg(not(feature = "std"))]
4mod smol_error_impls {
5 use crate::{IoError, ReadError, WriteError};
6 use ::smol::io::ErrorKind as E;
7
8 impl IoError for ::smol::io::Error {
9 fn should_retry(&self) -> bool {
10 self.kind() == E::Interrupted
11 }
12 }
13
14 impl ReadError for ::smol::io::Error {
15 fn eof() -> Self {
16 Self::from(E::UnexpectedEof)
17 }
18 }
19
20 impl WriteError for ::smol::io::Error {
21 fn write_zero() -> Self {
22 Self::from(E::WriteZero)
23 }
24 }
25}
26
27#[derive(Debug)]
32#[pin_project]
33pub struct Smol<T>(#[pin] pub T);
34
35impl_newtype! { Smol }
36
37impl_newtype_read! { Smol: ::smol::io::AsyncRead }
38
39impl<T> AsyncRead for Smol<T>
40where
41 T: ::smol::io::AsyncRead,
42{
43 type Error = ::smol::io::Error;
44
45 fn poll_read_slice(
46 self: Pin<&mut Self>,
47 cx: &mut Context,
48 buf: &mut [u8],
49 ) -> Poll<Result<usize, Self::Error>> {
50 let this = self.project();
51 this.0.poll_read(cx, buf)
52 }
53}
54
55impl_newtype_write! { Smol: ::smol::io::AsyncWrite }
56
57impl<T> AsyncWrite for Smol<T>
58where
59 T: ::smol::io::AsyncWrite,
60{
61 type Error = ::smol::io::Error;
62
63 fn poll_write_slice(
64 self: Pin<&mut Self>,
65 cx: &mut Context,
66 buf: &[u8],
67 ) -> Poll<Result<usize, Self::Error>> {
68 let this = self.project();
69 this.0.poll_write(cx, buf)
70 }
71
72 fn poll_flush_once(
73 self: Pin<&mut Self>,
74 cx: &mut Context,
75 ) -> Poll<Result<(), Self::Error>> {
76 let this = self.project();
77 this.0.poll_flush(cx)
78 }
79}