File tree 5 files changed +24
-22
lines changed
5 files changed +24
-22
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
13
13
### Fixed
14
14
- Fixed blanket impl of ` DelayUs ` not covering the ` delay_ms ` method.
15
15
16
+ ### Changed
17
+ - ` serial ` : traits now enforce all impls on the same struct have the same ` Error ` type.
18
+
16
19
## [ v1.0.0-alpha.6] - 2021-11-19
17
20
18
21
** * This is (also) an alpha release with breaking changes (sorry) ** *
Original file line number Diff line number Diff line change 143
143
//! // convenience type alias
144
144
//! pub type Serial1 = Serial<USART1>;
145
145
//!
146
- //! impl hal::serial::nb::Read<u8> for Serial<USART1> {
146
+ //! impl hal::serial::ErrorType for Serial<USART1> {
147
147
//! type Error = hal::serial::ErrorKind;
148
+ //! }
148
149
//!
150
+ //! impl hal::serial::nb::Read<u8> for Serial<USART1> {
149
151
//! fn read(&mut self) -> nb::Result<u8, Self::Error> {
150
152
//! // read the status register
151
153
//! let isr = self.usart.sr.read();
166
168
//! }
167
169
//!
168
170
//! impl hal::serial::nb::Write<u8> for Serial<USART1> {
169
- //! type Error = hal::serial::ErrorKind;
170
- //!
171
171
//! fn write(&mut self, byte: u8) -> nb::Result<(), Self::Error> {
172
172
//! // Similar to the `read` implementation
173
173
//! # Ok(())
387
387
//! # fn deref_mut(&mut self) -> &mut T { self.0 }
388
388
//! # }
389
389
//! # struct Serial1;
390
- //! # impl hal::serial::nb::Write<u8> for Serial1 {
390
+ //! # impl hal::serial::ErrorType for Serial1 {
391
391
//! # type Error = ErrorKind;
392
+ //! # }
393
+ //! # impl hal::serial::nb::Write<u8> for Serial1 {
392
394
//! # fn write(&mut self, _: u8) -> nb::Result<(), Self::Error> { Err(::nb::Error::WouldBlock) }
393
395
//! # fn flush(&mut self) -> nb::Result<(), Self::Error> { Err(::nb::Error::WouldBlock) }
394
396
//! # }
Original file line number Diff line number Diff line change 1
1
//! Blocking serial API
2
2
3
3
/// Write half of a serial interface (blocking variant)
4
- pub trait Write < Word = u8 > {
5
- /// The type of error that can occur when writing
6
- type Error : crate :: serial:: Error ;
7
-
4
+ pub trait Write < Word = u8 > : super :: ErrorType {
8
5
/// Writes a slice, blocking until everything has been written
9
6
///
10
7
/// An implementation can choose to buffer the write, returning `Ok(())`
@@ -20,8 +17,6 @@ pub trait Write<Word = u8> {
20
17
}
21
18
22
19
impl < T : Write < Word > , Word > Write < Word > for & mut T {
23
- type Error = T :: Error ;
24
-
25
20
fn write ( & mut self , buffer : & [ Word ] ) -> Result < ( ) , Self :: Error > {
26
21
T :: write ( self , buffer)
27
22
}
Original file line number Diff line number Diff line change @@ -63,3 +63,15 @@ impl core::fmt::Display for ErrorKind {
63
63
}
64
64
}
65
65
}
66
+
67
+ /// Serial error type trait
68
+ ///
69
+ /// This just defines the error type, to be used by the other traits.
70
+ pub trait ErrorType {
71
+ /// Error type
72
+ type Error : Error ;
73
+ }
74
+
75
+ impl < T : ErrorType > ErrorType for & mut T {
76
+ type Error = T :: Error ;
77
+ }
Original file line number Diff line number Diff line change 4
4
///
5
5
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
6
6
/// This can be encoded in this trait via the `Word` type parameter.
7
- pub trait Read < Word = u8 > {
8
- /// Read error
9
- type Error : crate :: serial:: Error ;
10
-
7
+ pub trait Read < Word = u8 > : super :: ErrorType {
11
8
/// Reads a single word from the serial interface
12
9
fn read ( & mut self ) -> nb:: Result < Word , Self :: Error > ;
13
10
}
14
11
15
12
impl < T : Read < Word > , Word > Read < Word > for & mut T {
16
- type Error = T :: Error ;
17
-
18
13
fn read ( & mut self ) -> nb:: Result < Word , Self :: Error > {
19
14
T :: read ( self )
20
15
}
21
16
}
22
17
23
18
/// Write half of a serial interface
24
- pub trait Write < Word = u8 > {
25
- /// Write error
26
- type Error : crate :: serial:: Error ;
27
-
19
+ pub trait Write < Word = u8 > : super :: ErrorType {
28
20
/// Writes a single word to the serial interface
29
21
fn write ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > ;
30
22
@@ -33,8 +25,6 @@ pub trait Write<Word = u8> {
33
25
}
34
26
35
27
impl < T : Write < Word > , Word > Write < Word > for & mut T {
36
- type Error = T :: Error ;
37
-
38
28
fn write ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > {
39
29
T :: write ( self , word)
40
30
}
You can’t perform that action at this time.
0 commit comments