-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Adding io::{Read, Write} traits in libcore? #68315
Comments
Yes, |
2 tasks
bors bot
added a commit
to tock/tock
that referenced
this issue
Jan 20, 2020
1548: Add kernel::debug::IoWrite trait and remove unsound str::from_utf8_unchecked (fix #1449) r=ppannuto a=gendx ### Pull Request Overview This pull request adds a new `IoWrite` trait in the kernel, to write arbitrary bytes instead of UTF-8 strings (fixes #1449). Until now, the `flush` function was using `str::from_utf8_unchecked`, even though the bytes are actually not UTF-8 (even with only UTF-8 input, the underlying ring buffer may wrap-around in the middle on a UTF-8 character). In practice, the underlying implementations work byte-by-byte to send debug output, so a more general trait to write byte slices can be plugged in. This `IoWrite` trait is similar to `std::io::Write`, except that the latter doesn't exist in `no_std` (because `std::io::Error` isn't compatible - see rust-lang/rust#68315 and rust-lang/rfcs#2262). ### Testing Strategy This pull request was tested by Travis. ### TODO or Help Wanted This pull request still needs support for byte-by-byte writing on the arty-e21 board. I'm not even sure the current `debug!` macro is what we want to do in a panic handler. ### Documentation Updated - [x] Updated the relevant files in `/docs`, or no updates are required. ### Formatting - [x] Ran `make formatall`. Co-authored-by: Guillaume Endignoux <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, libcore contains
core::fmt::Write
but (as far as I understand) nothing of thestd::io::
namespace.However,
core::fmt::Write
is more constrained thanstd::io::Write
, in that it only allows to write UTF-8 strings, as opposed to slices of bytes in general. It seems to me thatstd::io::Write
as a trait doesn't require any specific OS support (contrary toFile
,Stdout
, etc.), and as such would be useful in libcore and would integrate well there.For an example where it would be useful in a
no_std
context, see tock/tock#1449. In this case, one could essentially re-write theio::Write
trait, but this seems quite redundant (and wouldn't inter-operate with crates that require a genuineio::Write
in their API).In general, it seems to me that
std::io::{Read, Write}
, as well as a other utilities such asCursor
orBufReader
would have their place in libcore, to be able to use them inno_std
contexts. Or is there any technical difficultly that I missed?The text was updated successfully, but these errors were encountered: