Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(delegate)!: add a required lifetime bound on Delegate #454

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/riot-rs-embassy/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<T> Delegate<T> {
/// 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));
Expand All @@ -76,6 +76,8 @@ impl<T> Delegate<T> {
// 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(());
Expand Down
Loading