Re: [PATCH v5 2/3] rust: i2c: add manual I2C device creation abstractions
From: Igor Korotin
Date: Sat Sep 27 2025 - 12:43:49 EST
Hello Danilo
On 9/11/2025 9:34 PM, Danilo Krummrich wrote:
On Thu Sep 11, 2025 at 5:50 PM CEST, Igor Korotin wrote:
+impl I2cAdapter {
+ /// Gets pointer to an `i2c_adapter` by index.
+ pub fn get(index: i32) -> Result<ARef<Self>> {
Where do we get this index usually from? OF, ACPI, etc. I assume? I feel like it
could make sense to wrap it into a new type. Even though it is not safety
relevant it eliminates a source for mistakes.
It usually comes as predefined magic number in a platform driver info.
I'll define a specific type for this number for clearance.
+ }
+}
+
+impl<Ctx: device::DeviceContext> AsRef<I2cAdapter<Ctx>> for I2cAdapter<Ctx> {
+ fn as_ref(&self) -> &I2cAdapter<Ctx> {
+ &self
+ }
+}
This AsRef implementation doesn't seem to do anything?
I misunderstood the concept of the ARef<T> a little bit and used this as_ref() instead of just getting a reference by &adapter. I'll remove this in the next drop
Thanks for the review. All other comments are noted. I'll address them in the next drop as well
Cheers
Igor