Skip to content

Commit

Permalink
Merge pull request #517 from Dirbaio/eioa-slicewrit
Browse files Browse the repository at this point in the history
io-async: make slice write impl consistent with blocking impl.
  • Loading branch information
MabezDev authored Oct 24, 2023
2 parents 244f2b9 + ff1eb9c commit 53076d8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion embedded-io-async/src/impls/slice_mut.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::Write;
use core::mem;
use embedded_io::SliceWriteError;

use crate::Write;

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

0 comments on commit 53076d8

Please sign in to comment.