-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std: Add io
module again
#21835
std: Add io
module again
#21835
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
Note that rust-lang/rfcs#576 has not yet been merged, so this should hold off on merging until that happens. |
unsafe { | ||
let other = ptr::read(self); | ||
*self = &mut other[amt..]; | ||
} |
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 was unable to figure out a safe way of doing this, but I have a feeling one may be lurking somewhere, certainly open to suggestions!
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 works (see in playpen):
fn cut<T>(xs: &mut &mut [T], amt: usize) {
let original = mem::replace(xs, &mut []);
mem::replace(xs, &mut original[amt..]);
}
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.
Aha, thanks!
⌛ Testing commit 5cf9905 with merge 9830b16... |
💔 Test failed - auto-linux-64-x-android-t |
💔 Test failed - auto-win-32-opt |
💔 Test failed - auto-linux-32-opt |
@bors: retry |
⌛ Testing commit 5cf9905 with merge bc16888... |
This commit is an implementation of [RFC 576][rfc] which adds back the `std::io` module to the standard library. No functionality in `std::old_io` has been deprecated just yet, and the new `std::io` module is behind the same `io` feature gate. [rfc]: rust-lang/rfcs#576 A good bit of functionality was copied over from `std::old_io`, but many tweaks were required for the new method signatures. Behavior such as precisely when buffered objects call to the underlying object may have been tweaked slightly in the transition. All implementations were audited to use composition wherever possible. For example the custom `pos` and `cap` cursors in `BufReader` were removed in favor of just using `Cursor<Vec<u8>>`. A few liberties were taken during this implementation which were not explicitly spelled out in the RFC: * The old `LineBufferedWriter` is now named `LineWriter` * The internal representation of `Error` now favors OS error codes (a 0-allocation path) and contains a `Box` for extra semantic data. * The io prelude currently reexports `Seek` as `NewSeek` to prevent conflicts with the real prelude reexport of `old_io::Seek` * The `chars` method was moved from `BufReadExt` to `ReadExt`. * The `chars` iterator returns a custom error with a variant that explains that the data was not valid UTF-8.
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
⌛ Testing commit 5cf9905 with merge 661a65e... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
⌛ Testing commit 5cf9905 with merge b74eef5... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
1 similar comment
@bors: retry |
⌛ Testing commit 5cf9905 with merge 6a02f98... |
💔 Test failed - auto-linux-64-x-android-t |
@bors: retry |
|
||
// Semi-hack used to prevent LLVM from retaining any assumptions about | ||
// `dummy` over this function call | ||
unsafe fn black_box<T>(mut dummy: T) -> T { |
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.
Perhaps we should move this out of test into std::mem
or something
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.
It is not related to memory, though. I find test
be a better location for this.
This commit is an implementation of RFC 576 which adds back the
std::io
module to the standard library. No functionality in
std::old_io
has beendeprecated just yet, and the new
std::io
module is behind the sameio
feature gate.
A good bit of functionality was copied over from
std::old_io
, but many tweakswere required for the new method signatures. Behavior such as precisely when
buffered objects call to the underlying object may have been tweaked slightly in
the transition. All implementations were audited to use composition wherever
possible. For example the custom
pos
andcap
cursors inBufReader
wereremoved in favor of just using
Cursor<Vec<u8>>
.A few liberties were taken during this implementation which were not explicitly
spelled out in the RFC:
LineBufferedWriter
is now namedLineWriter
Error
now favors OS error codes (a0-allocation path) and contains a
Box
for extra semantic data.Seek
asNewSeek
to prevent conflictswith the real prelude reexport of
old_io::Seek
chars
method was moved fromBufReadExt
toReadExt
.chars
iterator returns a custom error with a variant that explains thatthe data was not valid UTF-8.