Skip to content

Commit

Permalink
Update example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rmja committed Oct 24, 2023
1 parent 9922556 commit 3f76fbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -21,3 +21,4 @@ embedded-io-async = { version = "0.6", optional = true }
embedded-io-async = { version = "0.6", features = ["std"] }
embedded-io-adapters = { version = "0.6", features = ["std"] }
tokio = { version = "1", features = ["macros", "rt"] }
tokio-test = "0.4"
20 changes: 13 additions & 7 deletions README.md
Expand Up @@ -9,11 +9,17 @@ The `buffered-io` crate implements buffering for the `embedded-io`/`embedded-io-
## Example

```rust
let uart_tx = ...;
let mut write_buf = [0; 120];
let buffering = BufferedWrite::new(uart_tx, &mut write_buf);
buffering.write(b"hello").await?; // This write is buffered
buffering.write(b" ").await?; // This write is also buffered
buffering.write(b"world").await?; // This write is also buffered
buffering.flush().await?; // The string "hello world" is written to uart in one write
#[cfg(feature = "async")]
tokio_test::block_on(async {
use buffered_io::asynch::BufferedWrite;
use embedded_io_async::Write;

let uart_tx = Vec::new(); // The underlying uart peripheral implementing Write to where buffered bytes are written
let mut write_buf = [0; 120];
let mut buffering = BufferedWrite::new(uart_tx, &mut write_buf);
buffering.write(b"hello").await.unwrap(); // This write is buffered
buffering.write(b" ").await.unwrap(); // This write is also buffered
buffering.write(b"world").await.unwrap(); // This write is also buffered
buffering.flush().await.unwrap(); // The string "hello world" is written to uart in one write
})
```

0 comments on commit 3f76fbc

Please sign in to comment.