Skip to content

Commit cb81053

Browse files
committed
fmt and clippy
1 parent c3b7b73 commit cb81053

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

src/bus.rs

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::address_from_pins;
2-
use embedded_hal::i2c::{ErrorType, I2c, Operation, SevenBitAddress};
32
use crate::prelude::MultiplexerError;
3+
use embedded_hal::i2c::{ErrorType, I2c, Operation, SevenBitAddress};
44

55
pub struct MultiplexerBus {
66
address: u8,
@@ -57,42 +57,63 @@ where
5757
}
5858
}
5959

60-
impl<I2C> ErrorType for BusPort<I2C> where I2C: I2c {
60+
impl<I2C> ErrorType for BusPort<I2C>
61+
where
62+
I2C: I2c,
63+
{
6164
type Error = MultiplexerError<I2C::Error>;
6265
}
6366

6467
impl<I2C> I2c for BusPort<I2C>
65-
where I2C: I2c
68+
where
69+
I2C: I2c,
6670
{
6771
fn read(&mut self, address: SevenBitAddress, read: &mut [u8]) -> Result<(), Self::Error> {
6872
self.open_port()?;
69-
self.bus.read(address, read).map_err(|err| MultiplexerError::I2CError(err))
73+
self.bus
74+
.read(address, read)
75+
.map_err(|err| MultiplexerError::I2CError(err))
7076
}
7177

7278
fn write(&mut self, address: SevenBitAddress, write: &[u8]) -> Result<(), Self::Error> {
7379
self.open_port()?;
74-
self.bus.write(address, write).map_err(|err| MultiplexerError::I2CError(err))
80+
self.bus
81+
.write(address, write)
82+
.map_err(|err| MultiplexerError::I2CError(err))
7583
}
7684

77-
fn write_read(&mut self, address: SevenBitAddress, write: &[u8], read: &mut [u8]) -> Result<(), Self::Error> {
85+
fn write_read(
86+
&mut self,
87+
address: SevenBitAddress,
88+
write: &[u8],
89+
read: &mut [u8],
90+
) -> Result<(), Self::Error> {
7891
self.open_port()?;
79-
self.bus.write_read(address, write, read).map_err(|err| MultiplexerError::I2CError(err))
92+
self.bus
93+
.write_read(address, write, read)
94+
.map_err(|err| MultiplexerError::I2CError(err))
8095
}
8196

82-
fn transaction(&mut self, address: SevenBitAddress, operations: &mut [Operation<'_>]) -> Result<(), Self::Error> {
97+
fn transaction(
98+
&mut self,
99+
address: SevenBitAddress,
100+
operations: &mut [Operation<'_>],
101+
) -> Result<(), Self::Error> {
83102
self.open_port()?;
84-
self.bus.transaction(address, operations).map_err(|err| MultiplexerError::I2CError(err))
103+
self.bus
104+
.transaction(address, operations)
105+
.map_err(|err| MultiplexerError::I2CError(err))
85106
}
86107
}
87108

88109
#[cfg(test)]
89110
mod test {
90111
extern crate alloc;
112+
use crate::prelude::*;
91113
use alloc::vec;
92114
use core::cell::RefCell;
93115
use embedded_hal::i2c::I2c;
94116
use embedded_hal_bus::i2c::RefCellDevice;
95-
use crate::prelude::*;
96117
use embedded_hal_mock::eh1::i2c::{Mock, Transaction};
97118

98119
#[test]
@@ -192,7 +213,7 @@ mod test {
192213
assert!(multiplexed_i2c_d.read(component_addr, &mut md).is_ok());
193214
assert_eq!(md, [0x45, 0x48]);
194215
}
195-
216+
196217
i2c.into_inner().done();
197218
}
198219

src/error.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use thiserror::Error;
44
pub type Result<T, I2cError> = core::result::Result<T, MultiplexerError<I2cError>>;
55

66
#[derive(Error, Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq)]
7-
pub enum MultiplexerError<I2cError> where I2cError: Error {
7+
pub enum MultiplexerError<I2cError>
8+
where
9+
I2cError: Error,
10+
{
811
#[error("Write Read I2C Error")]
912
WriteReadI2CError,
1013
#[error("Write I2C Error")]
@@ -14,14 +17,17 @@ pub enum MultiplexerError<I2cError> where I2cError: Error {
1417
#[error("Incorrect port supplied")]
1518
PortError,
1619
#[error("I2C Error")]
17-
I2CError(I2cError)
20+
I2CError(I2cError),
1821
}
1922

20-
impl<I2cError> Error for MultiplexerError<I2cError> where I2cError: Error {
23+
impl<I2cError> Error for MultiplexerError<I2cError>
24+
where
25+
I2cError: Error,
26+
{
2127
fn kind(&self) -> ErrorKind {
22-
match self {
28+
match self {
2329
Self::I2CError(e) => e.kind(),
24-
_ => ErrorKind::Other
30+
_ => ErrorKind::Other,
2531
}
2632
}
27-
}
33+
}

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ where
148148
}
149149

150150
fn i2c_write(&mut self, bytes: &[u8]) -> Result<(), I2C::Error> {
151-
self.i2c.write(self.address, bytes).map_err(|err| MultiplexerError::I2CError(err))
151+
self.i2c
152+
.write(self.address, bytes)
153+
.map_err(MultiplexerError::I2CError)
152154
}
153155
}
154156

0 commit comments

Comments
 (0)