Skip to content

Commit

Permalink
Adding tests, fixing API
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers committed Sep 7, 2023
1 parent bde7673 commit 0c0b2af
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions embedded-io/src/impls/slice_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,22 @@ impl Write for &mut [u8] {
Ok(())
}
}

#[cfg(test)]
mod test {
use crate::Write;

#[test]
fn basic_length() {
let mut buf = [0u8; 1024];
let len = write!(&mut buf[..], "Hello!").unwrap();
assert!(len == "Hello!".as_bytes().len());
}

#[test]
fn format_length() {
let mut buf = [0u8; 1024];
let len = write!(&mut buf[..], "Hello, {}!", "World").unwrap();
assert!(len == "Hello, World!".as_bytes().len());
}
}
2 changes: 1 addition & 1 deletion embedded-io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ pub trait Write: ErrorType {
/// If you are using [`WriteReady`] to avoid blocking, you should not use this function.
/// `WriteReady::write_ready()` returning true only guarantees the first call to `write()` will
/// not block, so this function may still block in subsequent calls.
fn write_all(&mut self, mut buf: &[u8]) -> Result<usize, WriteAllError<Self::Error>> {
fn write_all(&mut self, mut buf: &[u8]) -> Result<(), WriteAllError<Self::Error>> {
while !buf.is_empty() {
match self.write(buf) {
Ok(0) => return Err(WriteAllError::WriteZero),
Expand Down

0 comments on commit 0c0b2af

Please sign in to comment.