Skip to content

Commit 3581fb7

Browse files
authored
Merge pull request #47 from rust-embedded-community/fix/46/embedded-io-custom-buffers
Fixing embedded-io trait implementation
2 parents d8936bf + ccff775 commit 3581fb7

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
* Fixed an issue where the `embedded-io` traits were not implemented if custom buffers were used.
12+
1013
## [0.2.1] - 2024-03-06
1114

1215
### Added

src/io.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use super::SerialPort;
2+
use core::borrow::BorrowMut;
23
use usb_device::bus::UsbBus;
34

45
#[derive(Debug)]
@@ -22,11 +23,15 @@ impl embedded_io::Error for Error {
2223
}
2324
}
2425

25-
impl<Bus: UsbBus> embedded_io::ErrorType for SerialPort<'_, Bus> {
26+
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> embedded_io::ErrorType
27+
for SerialPort<'_, Bus, RS, WS>
28+
{
2629
type Error = Error;
2730
}
2831

29-
impl<Bus: UsbBus> embedded_io::Read for SerialPort<'_, Bus> {
32+
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> embedded_io::Read
33+
for SerialPort<'_, Bus, RS, WS>
34+
{
3035
fn read(&mut self, buf: &mut [u8]) -> Result<usize, Self::Error> {
3136
loop {
3237
match self.read(buf).map_err(From::from) {
@@ -40,14 +45,18 @@ impl<Bus: UsbBus> embedded_io::Read for SerialPort<'_, Bus> {
4045
}
4146
}
4247

43-
impl<Bus: UsbBus> embedded_io::ReadReady for SerialPort<'_, Bus> {
48+
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> embedded_io::ReadReady
49+
for SerialPort<'_, Bus, RS, WS>
50+
{
4451
fn read_ready(&mut self) -> Result<bool, Self::Error> {
4552
self.poll()?;
4653
Ok(self.read_buf.available_read() != 0)
4754
}
4855
}
4956

50-
impl<Bus: UsbBus> embedded_io::Write for SerialPort<'_, Bus> {
57+
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> embedded_io::Write
58+
for SerialPort<'_, Bus, RS, WS>
59+
{
5160
fn write(&mut self, buf: &[u8]) -> Result<usize, Self::Error> {
5261
if buf.is_empty() {
5362
return Ok(0);
@@ -69,7 +78,9 @@ impl<Bus: UsbBus> embedded_io::Write for SerialPort<'_, Bus> {
6978
}
7079
}
7180

72-
impl<Bus: UsbBus> embedded_io::WriteReady for SerialPort<'_, Bus> {
81+
impl<Bus: UsbBus, RS: BorrowMut<[u8]>, WS: BorrowMut<[u8]>> embedded_io::WriteReady
82+
for SerialPort<'_, Bus, RS, WS>
83+
{
7384
fn write_ready(&mut self) -> Result<bool, Self::Error> {
7485
Ok(self.write_buf.available_write() != 0)
7586
}

0 commit comments

Comments
 (0)