Skip to content

Commit 52dfc48

Browse files
committed
Add embedded_hal example
1 parent eb2e93c commit 52dfc48

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

examples/embedded_hal.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! This example does not actually do anything, but it shows that a serialport
2+
//! instance can be passed to functions / drivers that expect a type that
3+
//! implements the embedded-hal traits.
4+
5+
use embedded_hal_nb::serial;
6+
7+
fn take_reader<R: serial::Read<u8>>(_r: &R) {
8+
// do nothing, but things should typecheck
9+
}
10+
11+
fn take_writer<W: serial::Write<u8>>(_w: &W) {
12+
// do nothing, but things should typecheck
13+
}
14+
15+
fn main() {
16+
let port = serialport::new("/dev/null", 9600)
17+
.open()
18+
.expect("This example isn't meant for running. It just demonstrates compatibility with embedded-hal on a type level.");
19+
take_reader(&port);
20+
take_writer(&port);
21+
}

0 commit comments

Comments
 (0)