Skip to content
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

Merged
merged 1 commit into from
Feb 4, 2015
Merged

std: Add io module again #21835

merged 1 commit into from
Feb 4, 2015

Conversation

alexcrichton
Copy link
Member

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 been
deprecated just yet, and the new std::io module is behind the same io
feature gate.

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.

@rust-highfive
Copy link
Collaborator

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

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..];
}
Copy link
Member Author

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!

Copy link
Member

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..]);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, thanks!

@alexcrichton
Copy link
Member Author

@bors: r=aturon 5cf9905 p=1

@bors
Copy link
Contributor

bors commented Feb 3, 2015

⌛ Testing commit 5cf9905 with merge 9830b16...

@bors
Copy link
Contributor

bors commented Feb 3, 2015

💔 Test failed - auto-linux-64-x-android-t

@bors
Copy link
Contributor

bors commented Feb 3, 2015

💔 Test failed - auto-win-32-opt

@bors
Copy link
Contributor

bors commented Feb 3, 2015

💔 Test failed - auto-linux-32-opt

@alexcrichton
Copy link
Member Author

@bors: retry

@bors
Copy link
Contributor

bors commented Feb 4, 2015

⌛ Testing commit 5cf9905 with merge bc16888...

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Feb 4, 2015
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.
@bors
Copy link
Contributor

bors commented Feb 4, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: retry

@bors
Copy link
Contributor

bors commented Feb 4, 2015

⌛ Testing commit 5cf9905 with merge 661a65e...

@bors
Copy link
Contributor

bors commented Feb 4, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: retry

@bors
Copy link
Contributor

bors commented Feb 4, 2015

⌛ Testing commit 5cf9905 with merge b74eef5...

@bors
Copy link
Contributor

bors commented Feb 4, 2015

💔 Test failed - auto-linux-64-x-android-t

@alexcrichton
Copy link
Member Author

@bors: retry

1 similar comment
@alexcrichton
Copy link
Member Author

@bors: retry

@bors
Copy link
Contributor

bors commented Feb 4, 2015

⌛ Testing commit 5cf9905 with merge 6a02f98...

@bors
Copy link
Contributor

bors commented Feb 4, 2015

💔 Test failed - auto-linux-64-x-android-t

@sfackler
Copy link
Member

sfackler commented Feb 4, 2015

@bors: retry

@bors bors merged commit 5cf9905 into rust-lang:master Feb 4, 2015
@alexcrichton alexcrichton deleted the iov2 branch February 4, 2015 18:04
@aturon aturon mentioned this pull request Feb 18, 2015
91 tasks

// 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 {
Copy link
Contributor

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

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants