@@ -519,15 +519,24 @@ struct PartialResult<T, Err>(T, Err);
519
519
type NonatomicResult <S , T , Err > = Result <S , PartialResult <T , Err >>;
520
520
521
521
// Ergonomically throw out the partial result
522
- impl <T , Err > FromError <PartialResult <T , Err > for Err { ... }
522
+ impl <T , Err > FromError <PartialResult <T , Err >> for Err { ... }
523
523
```
524
524
525
525
The ` NonatomicResult ` type (which could use a shorter name)
526
526
encapsulates the common pattern of operations that may fail after
527
527
having made some progress. The ` PartialResult ` type then returns the
528
528
progress that was made along with the error, but with a ` FromError `
529
529
implementation that makes it trivial to throw out the partial result
530
- if desired .
530
+ if desired. For example, the following would be expected to compile:
531
+
532
+ ``` rust
533
+ fn write (buf : & [u8 ]) -> NonatomicResult <(), uint , Error > { /* ... */ }
534
+
535
+ fn write_bytes () -> Result <(), Error > {
536
+ try ! (write! (& [1 , 2 , 3 , 4 ]));
537
+ Ok (())
538
+ }
539
+ ```
531
540
532
541
### ` Reader `
533
542
[ Reader ] : #reader
@@ -649,7 +658,7 @@ throughout IO, we can go on to explore the modules in detail.
649
658
### ` core::io `
650
659
[ core::io ] : #coreio
651
660
652
- The ` io ` module is split into a the parts that can live in ` libcore `
661
+ The ` io ` module is split into the parts that can live in ` libcore `
653
662
(most of it) and the parts that are added in the ` std::io `
654
663
facade. Being able to move components into ` libcore ` at all is made
655
664
possible through the use of
@@ -696,7 +705,7 @@ impl<T: Writer> WriterExt for T {}
696
705
pub struct IterReader <T > { ... }
697
706
```
698
707
699
- As with ` std::iter ` , these adapters are object unsafe an hence placed
708
+ As with ` std::iter ` , these adapters are object unsafe and hence placed
700
709
in an extension trait with a blanket ` impl ` .
701
710
702
711
Note that the same ` ByRef ` type is used for both ` Reader ` and ` Writer `
@@ -731,7 +740,7 @@ readers and writers, as well as `copy`. These are updated as follows:
731
740
732
741
``` rust
733
742
// A reader that yields no bytes
734
- fn empty () -> Empty ;
743
+ fn empty () -> Empty ; // in theory just returns `impl Reader`
735
744
736
745
// A reader that yields `byte` repeatedly (generalizes today's ZeroReader)
737
746
fn repeat (byte : u8 ) -> Repeat ;
@@ -778,7 +787,8 @@ pub trait BufferedReader: Reader {
778
787
fn fill_buf (& mut self ) -> Result <& [u8 ], Self :: Err >;
779
788
fn consume (& mut self , amt : uint );
780
789
781
- // This should perhaps yield an iterator
790
+ // This should perhaps move to an iterator like `lines` where the iterator
791
+ // yields vectors read.
782
792
fn read_until (& mut self , byte : u8 ) -> NonatomicResult <Vec <u8 >, Vec <u8 >, Self :: Err > { ... }
783
793
}
784
794
0 commit comments