From 65feddc3c1848c0827d9a1240249075b480674dc Mon Sep 17 00:00:00 2001 From: Ole-Jeger Hoffstuen Date: Tue, 7 May 2024 10:36:23 +0200 Subject: [PATCH] Updated msg_type to be more readable --- src/linux.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/linux.rs b/src/linux.rs index c7555387..ae2bfba3 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -301,15 +301,15 @@ impl<'a> I2CTransfer<'a> for LinuxI2CDevice { /// Issue the provided sequence of I2C transactions fn transfer(&mut self, messages: &'a mut [Self::Message]) -> Result { let msg_type = |flag: u16| flag & I2CMessageFlags::READ.bits(); - let mut prev_msg_type = !msg_type(messages[0].flags); + let mut prev_msg_type = messages.first().map(|m| msg_type(m.flags)); for msg in messages.iter_mut() { msg.addr = self.slave_address; let cur_msg_type = msg_type(msg.flags); - if prev_msg_type == cur_msg_type { + if prev_msg_type.is_some_and(|prev| prev == cur_msg_type) { msg.flags |= I2CMessageFlags::NO_START.bits(); } else { - prev_msg_type = cur_msg_type; + prev_msg_type = Some(cur_msg_type); } } ffi::i2c_rdwr(self.as_raw_fd(), messages).map_err(From::from)