-
Notifications
You must be signed in to change notification settings - Fork 15
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
io::{Read,Write} traits #12
Conversation
src/io/write_all.rs
Outdated
/// | ||
/// let mut buffer = [0; 3]; | ||
/// { | ||
/// let writer = &mut &mut buffer[..]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&mut &mut
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed one, it does become an &mut &mut
during the method calls, but it doesn't need to be one to pass into write_all
.
src/io/read.rs
Outdated
/// buf.len()`. The `n` value indicates that the buffer `buf` has been filled in with `n` bytes | ||
/// of data from this source. If `n == 0 && buf.len() > 0` then it can be assumed that this | ||
/// reader has run out of data and will not be able service any future read calls. | ||
fn read(&mut self, buf: &mut [u8]) -> ::Result<usize, Self::Error>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like I'm missing something, but shouldn't the return type here (and elsewhere) be nb::Result<usize, Self::Error>
?
Is there a type alias somewhere that I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is referring to nb::Result
, it's just since this is defined in the nb
crate the crate root is just ::
. This was a leftover from initially implementing in embedded-hal
then doing minimal changes to get it compiling here, I'll switch to an actual use
of Result
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good lord that was silly of me. You linked from the embedded-hal
crate, and I didn't notice that this was a pull request for nb
rust-lang-nursery/portability-wg#12 may allow using the |
Thanks for the PR, @Nemo157 The Read and Write traits look good to me but I'm unsure about having the ReadExact and WriteAll In my mind operations that return nb::Result signal that they can't be started and completed right Once you have an operation that requires keeping program state then you should pick one of: blocking Now that sounds like you would have to repeat the logic when writing a futures based version of All this may sound like we should write everything using generators instead of using nb::Result but To elaborate on the last point in reactive code you usually write something like this: #[interrupt]
fn callback() {
let byte = SERIAL.read().unwrap();
// do stuff with byte
} The hardware will call the That being said I think there's a place for generators in reactive code: you could store the TL; DR IMO, nb::Result is for operations that require no program state and are completed in one |
I feel like it would be good to put the distinction between |
@austinglaser I agree |
@japaric that all sounds reasonable to me. I was able to find an actual potential integration point between I'll update this PR tomorrow with just the simple traits. |
FYI I proposed adding |
I finally got round to updating this to just the |
I mentioned on rust-embedded/embedded-hal#56 that it seems like a good idea for
embedded_hal
to provide base io traits similar to the ones instd
. After a bit more thought I decided that they should probably be somewhere a little more fundamental thanembedded_hal
so even non-HAL using code could be based off them.I'm not certain that
nb
itself should be the place to include these, or whether it would make sense to have a separatenb-io
crate for them.I'm relatively unhappy about adding a third set of these traits to the ecosystem (on top of the
std
ones and thefutures-io
ones, and maybe there are others I'm unaware of). It's also disappointing that these can't be compatible with thefutures-utils::io
adaptors, so like the exampleread_exact
andwrite_all
adaptors I've added they'll have to be rewritten fornb::io
. But without something like thefutures-io
crate switching to an associated error type like these to avoid thestd::io::Error
dependency, I don't see any other way to do this; and I really don't think the futures ecosystem would like the ergonomic hit introducing that associated type would bring.