Skip to content

Commit 8296af2

Browse files
committed
e-h-nb: inline hints, document fixes.
Signed-off-by: Zhouqi Jiang <[email protected]>
1 parent d81f7b8 commit 8296af2

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

embedded-hal-nb/src/serial.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Serial interface
1+
//! Serial interface.
22
3-
/// Serial error
3+
/// Serial error.
44
pub trait Error: core::fmt::Debug {
55
/// Convert error to a generic serial error kind
66
///
@@ -11,12 +11,13 @@ pub trait Error: core::fmt::Debug {
1111
}
1212

1313
impl Error for core::convert::Infallible {
14+
#[inline]
1415
fn kind(&self) -> ErrorKind {
1516
match *self {}
1617
}
1718
}
1819

19-
/// Serial error kind
20+
/// Serial error kind.
2021
///
2122
/// This represents a common set of serial operation errors. HAL implementations are
2223
/// free to define more specific or additional error types. However, by providing
@@ -38,12 +39,14 @@ pub enum ErrorKind {
3839
}
3940

4041
impl Error for ErrorKind {
42+
#[inline]
4143
fn kind(&self) -> ErrorKind {
4244
*self
4345
}
4446
}
4547

4648
impl core::fmt::Display for ErrorKind {
49+
#[inline]
4750
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
4851
match self {
4952
Self::Overrun => write!(f, "The peripheral receive buffer was overrun"),
@@ -61,7 +64,7 @@ impl core::fmt::Display for ErrorKind {
6164
}
6265
}
6366

64-
/// Serial error type trait
67+
/// Serial error type trait.
6568
///
6669
/// This just defines the error type, to be used by the other traits.
6770
pub trait ErrorType {
@@ -73,7 +76,7 @@ impl<T: ErrorType + ?Sized> ErrorType for &mut T {
7376
type Error = T::Error;
7477
}
7578

76-
/// Read half of a serial interface
79+
/// Read half of a serial interface.
7780
///
7881
/// Some serial interfaces support different data sizes (8 bits, 9 bits, etc.);
7982
/// This can be encoded in this trait via the `Word` type parameter.
@@ -83,25 +86,28 @@ pub trait Read<Word: Copy = u8>: ErrorType {
8386
}
8487

8588
impl<T: Read<Word> + ?Sized, Word: Copy> Read<Word> for &mut T {
89+
#[inline]
8690
fn read(&mut self) -> nb::Result<Word, Self::Error> {
8791
T::read(self)
8892
}
8993
}
9094

91-
/// Write half of a serial interface
95+
/// Write half of a serial interface.
9296
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.
9498
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error>;
9599

96-
/// Ensures that none of the previously written words are still buffered
100+
/// Ensures that none of the previously written words are still buffered.
97101
fn flush(&mut self) -> nb::Result<(), Self::Error>;
98102
}
99103

100104
impl<T: Write<Word> + ?Sized, Word: Copy> Write<Word> for &mut T {
105+
#[inline]
101106
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error> {
102107
T::write(self, word)
103108
}
104109

110+
#[inline]
105111
fn flush(&mut self) -> nb::Result<(), Self::Error> {
106112
T::flush(self)
107113
}
@@ -115,6 +121,7 @@ impl<Word, Error: self::Error> core::fmt::Write for dyn Write<Word, Error = Erro
115121
where
116122
Word: Copy + From<u8>,
117123
{
124+
#[inline]
118125
fn write_str(&mut self, s: &str) -> core::fmt::Result {
119126
let _ = s
120127
.bytes()

embedded-hal-nb/src/spi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ pub use embedded_hal::spi::{
44
Error, ErrorKind, ErrorType, Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3,
55
};
66

7-
/// Full duplex SPI (master mode)
7+
/// Full duplex SPI (master mode).
88
///
99
/// # Notes
1010
///
11-
/// - It's the task of the user of this interface to manage the slave select lines
11+
/// - It's the task of the user of this interface to manage the slave select lines.
1212
///
1313
/// - Due to how full duplex SPI works each `read` call must be preceded by a `write` call.
1414
///
@@ -32,10 +32,12 @@ pub trait FullDuplex<Word: Copy = u8>: ErrorType {
3232
}
3333

3434
impl<T: FullDuplex<Word> + ?Sized, Word: Copy> FullDuplex<Word> for &mut T {
35+
#[inline]
3536
fn read(&mut self) -> nb::Result<Word, Self::Error> {
3637
T::read(self)
3738
}
3839

40+
#[inline]
3941
fn write(&mut self, word: Word) -> nb::Result<(), Self::Error> {
4042
T::write(self, word)
4143
}

0 commit comments

Comments
 (0)