Skip to content

Commit ff1eb9c

Browse files
committed
io-async: make slice write impl consistent with blocking impl.
1 parent 244f2b9 commit ff1eb9c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

embedded-io-async/src/impls/slice_mut.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
use crate::Write;
21
use core::mem;
2+
use embedded_io::SliceWriteError;
3+
4+
use crate::Write;
35

46
/// Write is implemented for `&mut [u8]` by copying into the slice, overwriting
57
/// its data.
@@ -14,6 +16,9 @@ impl Write for &mut [u8] {
1416
#[inline]
1517
async fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
1618
let amt = core::cmp::min(buf.len(), self.len());
19+
if !buf.is_empty() && amt == 0 {
20+
return Err(SliceWriteError::Full);
21+
}
1722
let (a, b) = mem::take(self).split_at_mut(amt);
1823
a.copy_from_slice(&buf[..amt]);
1924
*self = b;

0 commit comments

Comments
 (0)