From 8fa63ac15ea2adc243fd6be70b70a9b5b25f8439 Mon Sep 17 00:00:00 2001
From: Diego Barrios Romero <eldruin@gmail.com>
Date: Wed, 5 Feb 2025 18:52:31 +0100
Subject: [PATCH 1/3] Derive common traits for public types

---
 CHANGELOG.md | 3 ++-
 src/linux.rs | 2 ++
 src/mock.rs  | 3 ++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 956fe90b..931041de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
 
 ## [Unreleased]
 
-- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference
+- Relax lifetime constraint on `I2CTransfer::transfer` `msgs` reference.
+- Derived common traits for public types.
 
 ## [v0.6.1] - 2024-05-09
 
diff --git a/src/linux.rs b/src/linux.rs
index 1917eacd..5ff18605 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -23,6 +23,7 @@ use std::path::Path;
 pub use core::I2CMessage;
 
 /// Concrete linux I2C device
+#[derive(Debug)]
 pub struct LinuxI2CDevice {
     devfile: File,
     slave_address: u16,
@@ -30,6 +31,7 @@ pub struct LinuxI2CDevice {
 }
 
 /// Linux I2C bus
+#[derive(Debug)]
 pub struct LinuxI2CBus {
     devfile: File,
 }
diff --git a/src/mock.rs b/src/mock.rs
index 45d3fb29..34c62d6b 100644
--- a/src/mock.rs
+++ b/src/mock.rs
@@ -13,6 +13,7 @@ use std::io;
 pub type I2CResult<T> = io::Result<T>;
 
 /// Mock I2C device register map
+#[derive(Debug, Clone, Copy)]
 pub struct I2CRegisterMap {
     registers: [u8; 0xFF],
     offset: usize,
@@ -67,7 +68,7 @@ impl I2CRegisterMap {
 }
 
 /// Mock I2C device exposing a register map
-#[derive(Default)]
+#[derive(Default, Debug, Clone, Copy)]
 pub struct MockI2CDevice {
     /// I2C register map
     pub regmap: I2CRegisterMap,

From 5470d8fc702cc06a31335a196c10a5b8daf821c1 Mon Sep 17 00:00:00 2001
From: Diego Barrios Romero <eldruin@gmail.com>
Date: Wed, 5 Feb 2025 18:53:47 +0100
Subject: [PATCH 2/3] Fix unused code warnings on other platforms

---
 examples/nunchuck.rs |  4 ++++
 examples/pca9956b.rs | 15 +++++++++------
 examples/sensors.rs  | 14 ++++++++------
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/examples/nunchuck.rs b/examples/nunchuck.rs
index 9af0242c..7462311f 100644
--- a/examples/nunchuck.rs
+++ b/examples/nunchuck.rs
@@ -57,6 +57,7 @@ mod nunchuck {
     // TODO: Move Nunchuck code out to be an actual sensor and add tests
 
     #[derive(Debug)]
+    #[allow(dead_code)]
     pub struct NunchuckReading {
         pub joystick_x: u8,
         pub joystick_y: u8,
@@ -186,9 +187,12 @@ mod nunchuck {
 #[cfg(any(target_os = "linux", target_os = "android"))]
 use nunchuck::*;
 
+#[cfg(any(target_os = "linux", target_os = "android"))]
 use docopt::Docopt;
+#[cfg(any(target_os = "linux", target_os = "android"))]
 use std::env::args;
 
+#[cfg(any(target_os = "linux", target_os = "android"))]
 const USAGE: &str = "
 Reading Wii Nunchuck data via Linux i2cdev.
 
diff --git a/examples/pca9956b.rs b/examples/pca9956b.rs
index c6661f59..66a9d00f 100644
--- a/examples/pca9956b.rs
+++ b/examples/pca9956b.rs
@@ -10,13 +10,12 @@ extern crate docopt;
 extern crate i2cdev;
 
 #[cfg(any(target_os = "linux", target_os = "android"))]
-use i2cdev::core::{I2CMessage, I2CTransfer};
-#[cfg(any(target_os = "linux", target_os = "android"))]
-use i2cdev::linux::{LinuxI2CBus, LinuxI2CMessage};
-
-use docopt::Docopt;
-use std::env::args;
+use i2cdev::{
+    core::{I2CMessage, I2CTransfer},
+    linux::{LinuxI2CBus, LinuxI2CMessage},
+};
 
+#[cfg(any(target_os = "linux", target_os = "android"))]
 const USAGE: &str = "
 Reads registers from a PCA9956B IC via Linux i2cdev.
 
@@ -32,6 +31,7 @@ Options:
   --version    Show version.
 ";
 
+#[cfg(any(target_os = "linux", target_os = "android"))]
 const ADDR: u16 = 0x20;
 
 #[cfg(not(any(target_os = "linux", target_os = "android")))]
@@ -39,6 +39,9 @@ fn main() {}
 
 #[cfg(any(target_os = "linux", target_os = "android"))]
 fn main() {
+    use docopt::Docopt;
+    use std::env::args;
+
     let args = Docopt::new(USAGE)
         .and_then(|d| d.argv(args()).parse())
         .unwrap_or_else(|e| e.exit());
diff --git a/examples/sensors.rs b/examples/sensors.rs
index 4fc9c0cb..1a52c591 100644
--- a/examples/sensors.rs
+++ b/examples/sensors.rs
@@ -17,13 +17,15 @@ extern crate byteorder;
 extern crate docopt;
 extern crate i2cdev;
 
+#[cfg(any(target_os = "linux", target_os = "android"))]
 use docopt::Docopt;
-use sensors::adxl345_accelerometer::*;
-use sensors::mpl115a2_barometer::*;
-use sensors::{Accelerometer, Barometer, Thermometer};
-use std::env::args;
-use std::thread;
-use std::time::Duration;
+#[cfg(any(target_os = "linux", target_os = "android"))]
+use sensors::{
+    adxl345_accelerometer::*, mpl115a2_barometer::*, Accelerometer, Barometer, Thermometer,
+};
+
+#[cfg(any(target_os = "linux", target_os = "android"))]
+use std::{env::args, thread, time::Duration};
 
 #[cfg(any(target_os = "linux", target_os = "android"))]
 use i2cdev::linux::*;

From 6613901e6733bdce787bec9c985a534172102ade Mon Sep 17 00:00:00 2001
From: Diego Barrios Romero <eldruin@gmail.com>
Date: Tue, 4 Mar 2025 11:03:20 +0100
Subject: [PATCH 3/3] Elide unnecessary lifetime

---
 src/linux.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/linux.rs b/src/linux.rs
index 5ff18605..82379a18 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -389,7 +389,7 @@ impl<'a> I2CMessage<'a> for LinuxI2CMessage<'a> {
     }
 }
 
-impl<'a> LinuxI2CMessage<'a> {
+impl LinuxI2CMessage<'_> {
     /// Set the target device address for the message
     pub fn with_address(self, slave_address: u16) -> Self {
         Self {