File tree 4 files changed +25
-5
lines changed
4 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
## Unreleased
9
9
10
10
- Add support for adapting ` BufRead ` from ` futures ` and ` tokio ` .
11
+ - Return an error when a wrapped ` std ` /` futures ` /` tokio ` ` write() ` call returns
12
+ ` Ok(0) ` to comply with ` embedded_io::Write ` requirements.
11
13
12
14
## 0.5.0 - 2023-08-06
13
15
14
- - First release
16
+ - First release
Original file line number Diff line number Diff line change @@ -57,7 +57,11 @@ impl<T: futures::io::AsyncBufRead + Unpin + ?Sized> embedded_io_async::BufRead f
57
57
58
58
impl < T : futures:: io:: AsyncWrite + Unpin + ?Sized > embedded_io_async:: Write for FromFutures < T > {
59
59
async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
60
- poll_fn ( |cx| Pin :: new ( & mut self . inner ) . poll_write ( cx, buf) ) . await
60
+ match poll_fn ( |cx| Pin :: new ( & mut self . inner ) . poll_write ( cx, buf) ) . await {
61
+ Ok ( 0 ) if !buf. is_empty ( ) => Err ( std:: io:: ErrorKind :: WriteZero . into ( ) ) ,
62
+ Ok ( n) => Ok ( n) ,
63
+ Err ( e) => Err ( e) ,
64
+ }
61
65
}
62
66
63
67
async fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
Original file line number Diff line number Diff line change 1
1
//! Adapters to/from `std::io` traits.
2
2
3
+ use embedded_io:: Error ;
4
+
3
5
/// Adapter from `std::io` traits.
4
6
#[ derive( Clone ) ]
5
7
pub struct FromStd < T : ?Sized > {
@@ -52,7 +54,11 @@ impl<T: std::io::BufRead + ?Sized> embedded_io::BufRead for FromStd<T> {
52
54
53
55
impl < T : std:: io:: Write + ?Sized > embedded_io:: Write for FromStd < T > {
54
56
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
55
- self . inner . write ( buf)
57
+ match self . inner . write ( buf) {
58
+ Ok ( 0 ) if !buf. is_empty ( ) => Err ( std:: io:: ErrorKind :: WriteZero . into ( ) ) ,
59
+ Ok ( n) => Ok ( n) ,
60
+ Err ( e) => Err ( e) ,
61
+ }
56
62
}
57
63
fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
58
64
self . inner . flush ( )
@@ -103,7 +109,11 @@ impl<T: embedded_io::Read + ?Sized> std::io::Read for ToStd<T> {
103
109
104
110
impl < T : embedded_io:: Write + ?Sized > std:: io:: Write for ToStd < T > {
105
111
fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , std:: io:: Error > {
106
- self . inner . write ( buf) . map_err ( to_std_error)
112
+ match self . inner . write ( buf) {
113
+ Ok ( n) => Ok ( n) ,
114
+ Err ( e) if e. kind ( ) == embedded_io:: ErrorKind :: WriteZero => Ok ( 0 ) ,
115
+ Err ( e) => Err ( to_std_error ( e) ) ,
116
+ }
107
117
}
108
118
fn flush ( & mut self ) -> Result < ( ) , std:: io:: Error > {
109
119
self . inner . flush ( ) . map_err ( to_std_error)
Original file line number Diff line number Diff line change @@ -68,7 +68,11 @@ impl<T: tokio::io::AsyncBufRead + Unpin + ?Sized> embedded_io_async::BufRead for
68
68
69
69
impl < T : tokio:: io:: AsyncWrite + Unpin + ?Sized > embedded_io_async:: Write for FromTokio < T > {
70
70
async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Self :: Error > {
71
- poll_fn ( |cx| Pin :: new ( & mut self . inner ) . poll_write ( cx, buf) ) . await
71
+ match poll_fn ( |cx| Pin :: new ( & mut self . inner ) . poll_write ( cx, buf) ) . await {
72
+ Ok ( 0 ) if !buf. is_empty ( ) => Err ( std:: io:: ErrorKind :: WriteZero . into ( ) ) ,
73
+ Ok ( n) => Ok ( n) ,
74
+ Err ( e) => Err ( e) ,
75
+ }
72
76
}
73
77
74
78
async fn flush ( & mut self ) -> Result < ( ) , Self :: Error > {
You can’t perform that action at this time.
0 commit comments