Skip to content

Commit 244d383

Browse files
committed
async/i2c: fix lifetimes on Transaction.
1 parent 173750c commit 244d383

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

embedded-hal-async/src/i2c.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
107107
) -> Self::WriteReadFuture<'a>;
108108

109109
/// Future returned by the `transaction` method.
110-
type TransactionFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
110+
type TransactionFuture<'a, 'b>: Future<Output = Result<(), Self::Error>> + 'a
111111
where
112-
Self: 'a;
112+
Self: 'a,
113+
'b: 'a;
113114

114115
/// Execute the provided operations on the I2C bus as a single transaction.
115116
///
@@ -124,11 +125,11 @@ pub trait I2c<A: AddressMode = SevenBitAddress>: ErrorType {
124125
/// - `SAD+R/W` = slave address followed by bit 1 to indicate reading or 0 to indicate writing
125126
/// - `SR` = repeated start condition
126127
/// - `SP` = stop condition
127-
fn transaction<'a>(
128+
fn transaction<'a, 'b>(
128129
&'a mut self,
129130
address: A,
130-
operations: &mut [Operation<'a>],
131-
) -> Self::TransactionFuture<'a>;
131+
operations: &'a mut [Operation<'b>],
132+
) -> Self::TransactionFuture<'a, 'b>;
132133
}
133134

134135
impl<A: AddressMode, T: I2c<A>> I2c<A> for &mut T {
@@ -164,16 +165,17 @@ impl<A: AddressMode, T: I2c<A>> I2c<A> for &mut T {
164165
T::write_read(self, address, bytes, buffer)
165166
}
166167

167-
type TransactionFuture<'a>
168+
type TransactionFuture<'a, 'b>
168169
where
169170
Self: 'a,
170-
= T::TransactionFuture<'a>;
171+
'b: 'a,
172+
= T::TransactionFuture<'a, 'b>;
171173

172-
fn transaction<'a>(
174+
fn transaction<'a, 'b>(
173175
&'a mut self,
174176
address: A,
175-
operations: &mut [Operation<'a>],
176-
) -> Self::TransactionFuture<'a> {
177+
operations: &'a mut [Operation<'b>],
178+
) -> Self::TransactionFuture<'a, 'b> {
177179
T::transaction(self, address, operations)
178180
}
179181
}

src/i2c.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<T: ErrorType> ErrorType for &mut T {
244244
/// Address mode (7-bit / 10-bit)
245245
///
246246
/// Note: This trait is sealed and should not be implemented outside of this crate.
247-
pub trait AddressMode: private::Sealed {}
247+
pub trait AddressMode: private::Sealed + 'static {}
248248

249249
/// 7-bit address mode type
250250
pub type SevenBitAddress = u8;

0 commit comments

Comments
 (0)