Skip to content

Commit f702d55

Browse files
committed
Merge pull request #5 from alexcrichton/pr
Updates from implementation and feedback:
2 parents 4fae980 + b8c941a commit f702d55

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

text/0517-io-os-reform.md

+32-26
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,8 @@ The `Writer` trait is cut down to even smaller size:
589589
```rust
590590
trait Write {
591591
fn write(&mut self, buf: &[u8]) -> Result<uint, Error>;
592+
fn flush(&mut self) -> Result<(), Error>;
592593

593-
fn flush(&mut self) -> Result<(), Error> { .. }
594594
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error> { .. }
595595
fn write_fmt(&mut self, fmt: &fmt::Arguments) -> Result<(), Error> { .. }
596596
}
@@ -661,7 +661,7 @@ trait ReadExt: Read {
661661
// ... eliding the methods already described above
662662

663663
// Postfix version of `(&mut self)`
664-
fn by_ref<'a>(&'a mut self) -> &mut Self { ... }
664+
fn by_ref(&mut self) -> &mut Self { ... }
665665

666666
// Read everything from `self`, then read from `next`
667667
fn chain<R: Read>(self, next: R) -> Chain<Self, R> { ... }
@@ -731,19 +731,18 @@ types:
731731

732732
```rust
733733
pub trait Seek {
734-
type Err;
735734
// returns the new position after seeking
736-
fn seek(&mut self, pos: SeekPos) -> Result<u64, Err>;
735+
fn seek(&mut self, pos: SeekFrom) -> Result<u64, Error>;
737736
}
738737

739-
pub enum SeekPos {
740-
FromStart(u64),
741-
FromEnd(i64),
742-
FromCur(i64),
738+
pub enum SeekFrom {
739+
Start(u64),
740+
End(i64),
741+
Current(i64),
743742
}
744743
```
745744

746-
The old `tell` function can be regained via `seek(SeekPos::FromCur(0))`.
745+
The old `tell` function can be regained via `seek(SeekFrom::Current(0))`.
747746

748747
#### Buffering
749748
[Buffering]: #buffering
@@ -788,12 +787,19 @@ strings) and is usually what you want when working with iterators.
788787

789788
The `BufReader`, `BufWriter` and `BufStream` types stay
790789
essentially as they are today, except that for streams and writers the
791-
`into_inner` method yields any errors encountered when flushing,
792-
together with the remaining data:
790+
`into_inner` method yields the structure back in the case of a flush error:
793791

794792
```rust
795793
// If flushing fails, you get the unflushed data back
796-
fn into_inner(self) -> Result<W, (Self, Error)>;
794+
fn into_inner(self) -> Result<W, IntoInnerError<Self>>;
795+
796+
pub struct IntoInnerError<W>(W, Error);
797+
798+
impl IntoInnerError<T> {
799+
pub fn error(&self) -> &Error { ... }
800+
pub fn into_inner(self) -> W { ... }
801+
}
802+
impl<W> FromError<IntoInnerError<W>> for Error { ... }
797803
```
798804

799805
#### `Cursor`
@@ -804,9 +810,9 @@ or `Write`. This is often useful when composing streams or creating test cases.
804810
This functionality primarily comes from the following implementations:
805811

806812
```rust
807-
impl<'a> Read for &'a [u8] { type Err = Void; ... }
808-
impl<'a> Write for &'a mut [u8] { type Err = Void; ... }
809-
impl Write for Vec<u8> { type Err = Void; ... }
813+
impl<'a> Read for &'a [u8] { ... }
814+
impl<'a> Write for &'a mut [u8] { ... }
815+
impl Write for Vec<u8> { ... }
810816
```
811817

812818
While efficient, none of these implementations support seeking (via an
@@ -829,20 +835,20 @@ impl<T> Cursor<T> {
829835
// Error indicating that a negative offset was seeked to.
830836
pub struct NegativeOffset;
831837

832-
impl Seek for Cursor<Vec<u8>> { type Err = NegativeOffset; ... }
833-
impl<'a> Seek for Cursor<&'a [u8]> { type Err = NegativeOffset; ... }
834-
impl<'a> Seek for Cursor<&'a mut [u8]> { type Err = NegativeOffset; ... }
838+
impl Seek for Cursor<Vec<u8>> { ... }
839+
impl<'a> Seek for Cursor<&'a [u8]> { ... }
840+
impl<'a> Seek for Cursor<&'a mut [u8]> { ... }
835841

836-
impl Read for Cursor<Vec<u8>> { type Err = Void; ... }
837-
impl<'a> Read for Cursor<&'a [u8]> { type Err = Void; ... }
838-
impl<'a> Read for Cursor<&'a mut [u8]> { type Err = Void; ... }
842+
impl Read for Cursor<Vec<u8>> { ... }
843+
impl<'a> Read for Cursor<&'a [u8]> { ... }
844+
impl<'a> Read for Cursor<&'a mut [u8]> { ... }
839845

840-
impl BufferedRead for Cursor<Vec<u8>> { type Err = Void; ... }
841-
impl<'a> BufferedRead for Cursor<&'a [u8]> { type Err = Void; ... }
842-
impl<'a> BufferedRead for Cursor<&'a mut [u8]> { type Err = Void; ... }
846+
impl BufRead for Cursor<Vec<u8>> { ... }
847+
impl<'a> BufRead for Cursor<&'a [u8]> { ... }
848+
impl<'a> BufRead for Cursor<&'a mut [u8]> { ... }
843849

844-
impl<'a> Write for Cursor<&'a mut [u8]> { type Err = Void; ... }
845-
impl Write for Cursor<Vec<u8>> { type Err = Void; ... }
850+
impl<'a> Write for Cursor<&'a mut [u8]> { ... }
851+
impl Write for Cursor<Vec<u8>> { ... }
846852
```
847853

848854
A sample implementation can be found in [a gist][cursor-impl]. Using one

0 commit comments

Comments
 (0)