blocking/spi: Don't return the same buffer back.#286
Conversation
|
r? @ryankurte (rust-highfive has picked a reviewer for you, use r? to override) |
a7365d1 to
a7c1233
Compare
|
One thing that I just thought of here. If the read buffers get switched over to |
|
True! The propsed change is what I feel makes most sense given the current convention of not using MaybeUninit or similar. Maybe you could open an issue on "add a way to read into uninitialized buffers" and we can discuss there :) |
|
Agreed. I noticed this recently as well, and was surprised. Eg this instead: /// Read multiple bytes to a buffer, blocking.
fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<(), Error> {
for word in words.iter_mut() {
nb::block!(self.write_one(word.clone()))?;
*word = nb::block!(self.read())?;
}
Ok(())
} |
a7c1233 to
1eebe4b
Compare
|
ping @eldruin @ryankurte @therealprof I believe this should be fairly uncontroversial. The question of "what about |
1eebe4b to
5cfb828
Compare
|
@japaric Since you added the API way back when, did you have any intentions with regards to this particular interface? Any objections to removing it? |
|
i guess without the returned subslice (or an |
|
As discussed last week we're going to merge this pending objections. @Dirbaio Would you mind fixing the conflicts? |
5cfb828 to
849801a
Compare
|
@therealprof rebased |
|
uh, CI is broken due to the |
|
Alright, #305 should fix CI, then we can merge this. |
therealprof
left a comment
There was a problem hiding this comment.
LGTM, thanks!
bors r+
287: spi: add Read and separate-buffers Transfer r=eldruin a=Dirbaio ~~Depends on #286~~ - Added spi::Read for only reading - Renamed Transfer to TransferInplace - Added a new Transfer, for reading+writing simultaneously with different buffers. Open question - ~~Should Transactional gain Read, Transfer (not-inplace) support?~~ yes, done Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This is a rather minor improvement to the blocking SPI Transfer trait, but that IMO is still worth it.
Old:
fn transfer<'w>(&mut self, words: &'w mut [W]) -> Result<&'w [W], Self::Error>New:
fn transfer(&mut self, words: &mut [W]) -> Result<(), Self::Error>It is redundant (and confusing IMO) to return back the same buffer the user has passed in. It allows for 2 ways of writing the same thing: use the returned buffer, or ignore it and use the buffer that was passed in. It's not obvious which is better, and from the docs it's not obvious that both are really the same either.
Also, with the old signature, it is possible for implementors to return a subslice of the buffer instead of the whole buffer. This would be arguably wrong and would break user code that assumes the entire buffer is returned. Not re-returning the buffer makes this mistake impossible.