Skip to content

Commit

Permalink
Add embedded_hal example
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Nov 13, 2022
1 parent faedbd5 commit 32031cb
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions examples/embedded_hal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! This example does not actually do anything, but it shows that a serialport
//! instance can be passed to functions / drivers that expect a type that
//! implements the embedded-hal traits.

use embedded_hal_nb::serial;

fn take_reader<R: serial::Read<u8>>(_r: &R) {
// do nothing, but things should typecheck
}

fn take_writer<W: serial::Write<u8>>(_w: &W) {
// do nothing, but things should typecheck
}

fn main() {
let port = serialport::new("/dev/null", 9600)
.open()
.expect("This example isn't meant for running. It just demonstrates compatibility with embedded-hal on a type level.");
take_reader(&port);
take_writer(&port);
}

0 comments on commit 32031cb

Please sign in to comment.