@@ -589,8 +589,8 @@ The `Writer` trait is cut down to even smaller size:
589
589
``` rust
590
590
trait Write {
591
591
fn write (& mut self , buf : & [u8 ]) -> Result <uint , Error >;
592
+ fn flush (& mut self ) -> Result <(), Error >;
592
593
593
- fn flush (& mut self ) -> Result <(), Error > { .. }
594
594
fn write_all (& mut self , buf : & [u8 ]) -> Result <(), Error > { .. }
595
595
fn write_fmt (& mut self , fmt : & fmt :: Arguments ) -> Result <(), Error > { .. }
596
596
}
@@ -661,7 +661,7 @@ trait ReadExt: Read {
661
661
// ... eliding the methods already described above
662
662
663
663
// Postfix version of `(&mut self)`
664
- fn by_ref <' a >( & ' a mut self ) -> & mut Self { ... }
664
+ fn by_ref ( & mut self ) -> & mut Self { ... }
665
665
666
666
// Read everything from `self`, then read from `next`
667
667
fn chain <R : Read >(self , next : R ) -> Chain <Self , R > { ... }
@@ -731,19 +731,18 @@ types:
731
731
732
732
```rust
733
733
pub trait Seek {
734
- type Err ;
735
734
// 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 >;
737
736
}
738
737
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 ),
743
742
}
744
743
```
745
744
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)) ` .
747
746
748
747
#### Buffering
749
748
[ Buffering ] : #buffering
@@ -788,12 +787,19 @@ strings) and is usually what you want when working with iterators.
788
787
789
788
The ` BufReader ` , ` BufWriter ` and ` BufStream ` types stay
790
789
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:
793
791
794
792
``` rust
795
793
// 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 { ... }
797
803
```
798
804
799
805
#### ` Cursor `
@@ -804,9 +810,9 @@ or `Write`. This is often useful when composing streams or creating test cases.
804
810
This functionality primarily comes from the following implementations:
805
811
806
812
``` 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 > { ... }
810
816
```
811
817
812
818
While efficient, none of these implementations support seeking (via an
@@ -829,20 +835,20 @@ impl<T> Cursor<T> {
829
835
// Error indicating that a negative offset was seeked to.
830
836
pub struct NegativeOffset ;
831
837
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 ]> { ... }
835
841
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 ]> { ... }
839
845
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 ]> { ... }
843
849
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 >> { ... }
846
852
```
847
853
848
854
A sample implementation can be found in [ a gist] [ cursor-impl ] . Using one
0 commit comments