Use named imports within function to make code easier to read
This commit is contained in:
parent
b52e9a60eb
commit
bb5fcce0a0
1 changed files with 9 additions and 9 deletions
|
@ -411,7 +411,7 @@ impl FrameOptions {
|
||||||
fn operation_frames<'a, 'b: 'a>(
|
fn operation_frames<'a, 'b: 'a>(
|
||||||
operations: &'a mut [embedded_hal_1::i2c::Operation<'b>],
|
operations: &'a mut [embedded_hal_1::i2c::Operation<'b>],
|
||||||
) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, FrameOptions)>, Error> {
|
) -> Result<impl IntoIterator<Item = (&'a mut embedded_hal_1::i2c::Operation<'b>, FrameOptions)>, Error> {
|
||||||
use embedded_hal_1::i2c::Operation;
|
use embedded_hal_1::i2c::Operation::{Read, Write};
|
||||||
|
|
||||||
// Check empty read buffer before starting transaction. Otherwise, we would risk halting with an
|
// Check empty read buffer before starting transaction. Otherwise, we would risk halting with an
|
||||||
// error in the middle of the transaction.
|
// error in the middle of the transaction.
|
||||||
|
@ -420,8 +420,8 @@ fn operation_frames<'a, 'b: 'a>(
|
||||||
// at least one byte remains in the final (merged) read operation, but that makes the logic more
|
// at least one byte remains in the final (merged) read operation, but that makes the logic more
|
||||||
// complicated and error-prone.
|
// complicated and error-prone.
|
||||||
if operations.iter().any(|op| match op {
|
if operations.iter().any(|op| match op {
|
||||||
Operation::Read(read) => read.is_empty(),
|
Read(read) => read.is_empty(),
|
||||||
Operation::Write(_) => false,
|
Write(_) => false,
|
||||||
}) {
|
}) {
|
||||||
return Err(Error::Overrun);
|
return Err(Error::Overrun);
|
||||||
}
|
}
|
||||||
|
@ -452,12 +452,12 @@ fn operation_frames<'a, 'b: 'a>(
|
||||||
// because the resulting frame options are identical for write operations.
|
// because the resulting frame options are identical for write operations.
|
||||||
let frame = match (first_frame, next_op) {
|
let frame = match (first_frame, next_op) {
|
||||||
(true, None) => FrameOptions::FirstAndLastFrame,
|
(true, None) => FrameOptions::FirstAndLastFrame,
|
||||||
(true, Some(Operation::Read(_))) => FrameOptions::FirstAndNextFrame,
|
(true, Some(Read(_))) => FrameOptions::FirstAndNextFrame,
|
||||||
(true, Some(Operation::Write(_))) => FrameOptions::FirstFrame,
|
(true, Some(Write(_))) => FrameOptions::FirstFrame,
|
||||||
//
|
//
|
||||||
(false, None) => FrameOptions::LastFrame,
|
(false, None) => FrameOptions::LastFrame,
|
||||||
(false, Some(Operation::Read(_))) => FrameOptions::NextFrame,
|
(false, Some(Read(_))) => FrameOptions::NextFrame,
|
||||||
(false, Some(Operation::Write(_))) => FrameOptions::LastFrameNoStop,
|
(false, Some(Write(_))) => FrameOptions::LastFrameNoStop,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Pre-calculate if `next_op` is the first operation of its type. We do this here and not at
|
// Pre-calculate if `next_op` is the first operation of its type. We do this here and not at
|
||||||
|
@ -465,8 +465,8 @@ fn operation_frames<'a, 'b: 'a>(
|
||||||
// anymore in the next iteration.
|
// anymore in the next iteration.
|
||||||
next_first_frame = match (&op, next_op) {
|
next_first_frame = match (&op, next_op) {
|
||||||
(_, None) => false,
|
(_, None) => false,
|
||||||
(Operation::Read(_), Some(Operation::Write(_))) | (Operation::Write(_), Some(Operation::Read(_))) => true,
|
(Read(_), Some(Write(_))) | (Write(_), Some(Read(_))) => true,
|
||||||
(Operation::Read(_), Some(Operation::Read(_))) | (Operation::Write(_), Some(Operation::Write(_))) => false,
|
(Read(_), Some(Read(_))) | (Write(_), Some(Write(_))) => false,
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((op, frame))
|
Some((op, frame))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue