Skip to content

Commit

Permalink
Fix clippy issues (#40)
Browse files Browse the repository at this point in the history
* Fix clippy issues

The result of running `cargo clippy --fix --all-targets --all-features`
twice.

* Manually fix another clippy issue

    warning: unnecessary `if let` since only the `Ok` variant of the iterator element is used
      --> examples/monitor-shtc3.rs:43:9
       |
    43 |           for key in io::stdin().keys() {
       |           ^          ------------------ help: try: `io::stdin().keys().flatten()`
       |  _________|
       | |
    44 | |             if let Ok(Key::Ctrl('c')) = key {
    45 | |                 running.store(false, Ordering::SeqCst);
    46 | |                 break;
    47 | |             }
    48 | |         }
       | |_________^
       |
    help: ...and remove the `if let` statement in the for loop
      --> examples/monitor-shtc3.rs:44:13
       |
    44 | /             if let Ok(Key::Ctrl('c')) = key {
    45 | |                 running.store(false, Ordering::SeqCst);
    46 | |                 break;
    47 | |             }
       | |_____________^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
       = note: `#[warn(clippy::manual_flatten)]` on by default
  • Loading branch information
rnestler committed May 13, 2024
1 parent ee881d0 commit 0cfcb5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions examples/monitor-shtc3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ fn main() -> Result<(), io::Error> {

// Handle Ctrl-c
thread::spawn(move || {
for key in io::stdin().keys() {
if let Ok(Key::Ctrl('c')) = key {
for key in io::stdin().keys().flatten() {
if Key::Ctrl('c') == key {
running.store(false, Ordering::SeqCst);
break;
}
Expand Down Expand Up @@ -147,7 +147,7 @@ fn show_chart<B: Backend>(
.name("Low power mode")
.marker(Marker::Braille)
.style(Style::default().fg(color_lowpwr))
.data(&data_lowpwr),
.data(data_lowpwr),
Dataset::default()
.name("Normal mode")
.marker(Marker::Dot)
Expand Down Expand Up @@ -175,7 +175,7 @@ fn show_chart<B: Backend>(

fn render(terminal: &mut Terminal<CrosstermBackend<RawTerminal<Stdout>>>, data: &Data) {
terminal
.draw(|mut f| {
.draw(|f| {
let chunks = Layout::default()
.direction(Direction::Vertical)
.margin(1)
Expand Down Expand Up @@ -216,7 +216,7 @@ fn render(terminal: &mut Terminal<CrosstermBackend<RawTerminal<Stdout>>>, data:
Color::Red,
temp_lowpwr.as_slice(),
Color::Magenta,
&mut f,
f,
chunks[0],
);
show_chart(
Expand All @@ -226,7 +226,7 @@ fn render(terminal: &mut Terminal<CrosstermBackend<RawTerminal<Stdout>>>, data:
Color::Blue,
humi_lowpwr.as_slice(),
Color::Cyan,
&mut f,
f,
chunks[1],
);
})
Expand Down
12 changes: 6 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ mod tests {
let test_data = [
(0x0000, -45000),
// Datasheet setion 5.11 "Conversion of Sensor Output"
(((0b0110_0100 as u16) << 8) | 0b1000_1011, 23730),
((0b0110_0100_u16 << 8) | 0b1000_1011, 23730),
];
for td in &test_data {
assert_eq!(convert_temperature(td.0), td.1);
Expand All @@ -111,7 +111,7 @@ mod tests {
let test_data = [
(0x0000, 0),
// Datasheet setion 5.11 "Conversion of Sensor Output"
(((0b1010_0001 as u16) << 8) | 0b0011_0011, 62968),
((0b1010_0001_u16 << 8) | 0b0011_0011, 62968),
];
for td in &test_data {
assert_eq!(convert_humidity(td.0), td.1);
Expand All @@ -122,8 +122,8 @@ mod tests {
#[test]
fn measurement_conversion() {
// Datasheet setion 5.11 "Conversion of Sensor Output"
let temperature = convert_temperature(((0b0110_0100 as u16) << 8) | 0b1000_1011);
let humidity = convert_humidity(((0b1010_0001 as u16) << 8) | 0b0011_0011);
let temperature = convert_temperature((0b0110_0100_u16 << 8) | 0b1000_1011);
let humidity = convert_humidity((0b1010_0001_u16 << 8) | 0b0011_0011);
assert_eq!(temperature, 23730);
assert_eq!(humidity, 62968);
}
Expand All @@ -146,8 +146,8 @@ mod tests {
fn measurement_from_into() {
// Datasheet setion 5.11 "Conversion of Sensor Output"
let raw = RawMeasurement {
temperature: ((0b0110_0100 as u16) << 8) | 0b1000_1011,
humidity: ((0b1010_0001 as u16) << 8) | 0b0011_0011,
temperature: (0b0110_0100_u16 << 8) | 0b1000_1011,
humidity: (0b1010_0001_u16 << 8) | 0b0011_0011,
};

// std::convert::From
Expand Down

0 comments on commit 0cfcb5d

Please sign in to comment.