Skip to content

Commit

Permalink
io-async: make slice write impl consistent with blocking impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 22, 2023
1 parent 244f2b9 commit ff1eb9c
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 ff1eb9c

Please sign in to comment.