Skip to content

Commit 73404a5

Browse files
authored
Merge pull request #90 from eldruin/common-traits
Derive common traits for public types + warnings fixes
2 parents 69121a8 + 6613901 commit 73404a5

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
88

99
## [Unreleased]
1010

11-
- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference
11+
- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference.
12+
- Derived common traits for public types.
1213

1314
## [v0.6.1] - 2024-05-09
1415

examples/nunchuck.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ mod nunchuck {
5757
// TODO: Move Nunchuck code out to be an actual sensor and add tests
5858

5959
#[derive(Debug)]
60+
#[allow(dead_code)]
6061
pub struct NunchuckReading {
6162
pub joystick_x: u8,
6263
pub joystick_y: u8,
@@ -186,9 +187,12 @@ mod nunchuck {
186187
#[cfg(any(target_os = "linux", target_os = "android"))]
187188
use nunchuck::*;
188189

190+
#[cfg(any(target_os = "linux", target_os = "android"))]
189191
use docopt::Docopt;
192+
#[cfg(any(target_os = "linux", target_os = "android"))]
190193
use std::env::args;
191194

195+
#[cfg(any(target_os = "linux", target_os = "android"))]
192196
const USAGE: &str = "
193197
Reading Wii Nunchuck data via Linux i2cdev.
194198

examples/pca9956b.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ extern crate docopt;
1010
extern crate i2cdev;
1111

1212
#[cfg(any(target_os = "linux", target_os = "android"))]
13-
use i2cdev::core::{I2CMessage, I2CTransfer};
14-
#[cfg(any(target_os = "linux", target_os = "android"))]
15-
use i2cdev::linux::{LinuxI2CBus, LinuxI2CMessage};
16-
17-
use docopt::Docopt;
18-
use std::env::args;
13+
use i2cdev::{
14+
core::{I2CMessage, I2CTransfer},
15+
linux::{LinuxI2CBus, LinuxI2CMessage},
16+
};
1917

18+
#[cfg(any(target_os = "linux", target_os = "android"))]
2019
const USAGE: &str = "
2120
Reads registers from a PCA9956B IC via Linux i2cdev.
2221
@@ -32,13 +31,17 @@ Options:
3231
--version Show version.
3332
";
3433

34+
#[cfg(any(target_os = "linux", target_os = "android"))]
3535
const ADDR: u16 = 0x20;
3636

3737
#[cfg(not(any(target_os = "linux", target_os = "android")))]
3838
fn main() {}
3939

4040
#[cfg(any(target_os = "linux", target_os = "android"))]
4141
fn main() {
42+
use docopt::Docopt;
43+
use std::env::args;
44+
4245
let args = Docopt::new(USAGE)
4346
.and_then(|d| d.argv(args()).parse())
4447
.unwrap_or_else(|e| e.exit());

examples/sensors.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ extern crate byteorder;
1717
extern crate docopt;
1818
extern crate i2cdev;
1919

20+
#[cfg(any(target_os = "linux", target_os = "android"))]
2021
use docopt::Docopt;
21-
use sensors::adxl345_accelerometer::*;
22-
use sensors::mpl115a2_barometer::*;
23-
use sensors::{Accelerometer, Barometer, Thermometer};
24-
use std::env::args;
25-
use std::thread;
26-
use std::time::Duration;
22+
#[cfg(any(target_os = "linux", target_os = "android"))]
23+
use sensors::{
24+
adxl345_accelerometer::*, mpl115a2_barometer::*, Accelerometer, Barometer, Thermometer,
25+
};
26+
27+
#[cfg(any(target_os = "linux", target_os = "android"))]
28+
use std::{env::args, thread, time::Duration};
2729

2830
#[cfg(any(target_os = "linux", target_os = "android"))]
2931
use i2cdev::linux::*;

src/linux.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ use std::path::Path;
2323
pub use core::I2CMessage;
2424

2525
/// Concrete linux I2C device
26+
#[derive(Debug)]
2627
pub struct LinuxI2CDevice {
2728
devfile: File,
2829
slave_address: u16,
2930
pec: bool,
3031
}
3132

3233
/// Linux I2C bus
34+
#[derive(Debug)]
3335
pub struct LinuxI2CBus {
3436
devfile: File,
3537
}
@@ -387,7 +389,7 @@ impl<'a> I2CMessage<'a> for LinuxI2CMessage<'a> {
387389
}
388390
}
389391

390-
impl<'a> LinuxI2CMessage<'a> {
392+
impl LinuxI2CMessage<'_> {
391393
/// Set the target device address for the message
392394
pub fn with_address(self, slave_address: u16) -> Self {
393395
Self {

src/mock.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::io;
1313
pub type I2CResult<T> = io::Result<T>;
1414

1515
/// Mock I2C device register map
16+
#[derive(Debug, Clone, Copy)]
1617
pub struct I2CRegisterMap {
1718
registers: [u8; 0xFF],
1819
offset: usize,
@@ -67,7 +68,7 @@ impl I2CRegisterMap {
6768
}
6869

6970
/// Mock I2C device exposing a register map
70-
#[derive(Default)]
71+
#[derive(Default, Debug, Clone, Copy)]
7172
pub struct MockI2CDevice {
7273
/// I2C register map
7374
pub regmap: I2CRegisterMap,

0 commit comments

Comments
 (0)