async/spi: replace the "give back the Bus" hack with a raw pointer. #380
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The async SPI trait contains a "hack" to workaround limitations in Rust's borrow checker: #347
It turns out the hack doesn't allow many shared bus implementations, for example when using an async Mutex: The
transaction
method gets&'a mut self
, and the closure wants&'a mut Self::Bus
. This only works if the Bus is a direct field inself
. In the mutex case, the Bus has to come from inside theMutexGuard
, so it'll live for less than'a
.See https://gist.github.com/kalkyl/ad3075182d610e7b413b8bbe1228ab90 which fails with the following error:
This is an alternative hack. If lifetimes don't work, simply don't use lifetimes at all!
unsafe{}
in all callers of transaction (but these should be rare, many users will use theSpiDeviceExt
helpers.?
inside the closure for error handling.cc @kalkyl