1
- //! Serial interface
1
+ //! Serial interface.
2
2
3
- /// Serial error
3
+ /// Serial error.
4
4
pub trait Error : core:: fmt:: Debug {
5
5
/// Convert error to a generic serial error kind
6
6
///
@@ -11,12 +11,13 @@ pub trait Error: core::fmt::Debug {
11
11
}
12
12
13
13
impl Error for core:: convert:: Infallible {
14
+ #[ inline]
14
15
fn kind ( & self ) -> ErrorKind {
15
16
match * self { }
16
17
}
17
18
}
18
19
19
- /// Serial error kind
20
+ /// Serial error kind.
20
21
///
21
22
/// This represents a common set of serial operation errors. HAL implementations are
22
23
/// free to define more specific or additional error types. However, by providing
@@ -38,12 +39,14 @@ pub enum ErrorKind {
38
39
}
39
40
40
41
impl Error for ErrorKind {
42
+ #[ inline]
41
43
fn kind ( & self ) -> ErrorKind {
42
44
* self
43
45
}
44
46
}
45
47
46
48
impl core:: fmt:: Display for ErrorKind {
49
+ #[ inline]
47
50
fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> core:: fmt:: Result {
48
51
match self {
49
52
Self :: Overrun => write ! ( f, "The peripheral receive buffer was overrun" ) ,
@@ -61,7 +64,7 @@ impl core::fmt::Display for ErrorKind {
61
64
}
62
65
}
63
66
64
- /// Serial error type trait
67
+ /// Serial error type trait.
65
68
///
66
69
/// This just defines the error type, to be used by the other traits.
67
70
pub trait ErrorType {
@@ -73,7 +76,7 @@ impl<T: ErrorType + ?Sized> ErrorType for &mut T {
73
76
type Error = T :: Error ;
74
77
}
75
78
76
- /// Read half of a serial interface
79
+ /// Read half of a serial interface.
77
80
///
78
81
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
79
82
/// This can be encoded in this trait via the `Word` type parameter.
@@ -83,25 +86,28 @@ pub trait Read<Word: Copy = u8>: ErrorType {
83
86
}
84
87
85
88
impl < T : Read < Word > + ?Sized , Word : Copy > Read < Word > for & mut T {
89
+ #[ inline]
86
90
fn read ( & mut self ) -> nb:: Result < Word , Self :: Error > {
87
91
T :: read ( self )
88
92
}
89
93
}
90
94
91
- /// Write half of a serial interface
95
+ /// Write half of a serial interface.
92
96
pub trait Write < Word : Copy = u8 > : ErrorType {
93
- /// Writes a single word to the serial interface
97
+ /// Writes a single word to the serial interface.
94
98
fn write ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > ;
95
99
96
- /// Ensures that none of the previously written words are still buffered
100
+ /// Ensures that none of the previously written words are still buffered.
97
101
fn flush ( & mut self ) -> nb:: Result < ( ) , Self :: Error > ;
98
102
}
99
103
100
104
impl < T : Write < Word > + ?Sized , Word : Copy > Write < Word > for & mut T {
105
+ #[ inline]
101
106
fn write ( & mut self , word : Word ) -> nb:: Result < ( ) , Self :: Error > {
102
107
T :: write ( self , word)
103
108
}
104
109
110
+ #[ inline]
105
111
fn flush ( & mut self ) -> nb:: Result < ( ) , Self :: Error > {
106
112
T :: flush ( self )
107
113
}
@@ -115,6 +121,7 @@ impl<Word, Error: self::Error> core::fmt::Write for dyn Write<Word, Error = Erro
115
121
where
116
122
Word : Copy + From < u8 > ,
117
123
{
124
+ #[ inline]
118
125
fn write_str ( & mut self , s : & str ) -> core:: fmt:: Result {
119
126
let _ = s
120
127
. bytes ( )
0 commit comments