From b171a86e873ac7fd4b738c836844555cf20df647 Mon Sep 17 00:00:00 2001 From: ROMemories <152802150+ROMemories@users.noreply.github.com> Date: Tue, 8 Oct 2024 16:03:12 +0200 Subject: [PATCH] fix(delegate)!: add a required lifetime bound on `Delegate` --- src/riot-rs-embassy/src/delegate.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/riot-rs-embassy/src/delegate.rs b/src/riot-rs-embassy/src/delegate.rs index 626bc955e..1f19952b1 100644 --- a/src/riot-rs-embassy/src/delegate.rs +++ b/src/riot-rs-embassy/src/delegate.rs @@ -55,7 +55,7 @@ impl Delegate { /// Lends an object. /// /// This blocks until another task called [`with()`](Delegate::with). - pub async fn lend(&self, something: &mut T) { + pub async fn lend<'a, 'b: 'a>(&'a self, something: &'b mut T) { let spawner = Spawner::for_current_executor().await; self.send .signal(SendCell::new(something as *mut T, spawner)); @@ -76,6 +76,8 @@ impl Delegate { // This function waits for the `self.send` signal, uses the dereferenced only inside the // closure, then signals `self.reply` // => the mutable reference is never used more than once + // - the lifetime bound on `lend` enforces that the raw pointer outlives this `Delegate` + // instance // TODO: it is actually possible to call `with()` twice, which breaks assumptions. let result = func(unsafe { data.get(spawner).unwrap().as_mut().unwrap() }); self.reply.signal(());