File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed
branches/try2/src/libstd/io Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: 3c06a0328a3c6824ff7578a6da46e133e9399854
8
+ refs/heads/try2: 00f9263914da3d18c556d7ebc3941f9638721ac2
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -964,6 +964,42 @@ pub trait Writer {
964
964
/// decide whether their stream needs to be buffered or not.
965
965
fn flush ( & mut self ) -> IoResult < ( ) > { Ok ( ( ) ) }
966
966
967
+ /// Writes a formatted string into this writer, returning any error
968
+ /// encountered.
969
+ ///
970
+ /// This method is primarily used to interface with the `format_args!`
971
+ /// macro, but it is rare that this should explicitly be called. The
972
+ /// `write!` macro should be favored to invoke this method instead.
973
+ ///
974
+ /// # Errors
975
+ ///
976
+ /// This function will return any I/O error reported while formatting.
977
+ fn write_fmt ( & mut self , fmt : & fmt:: Arguments ) -> IoResult < ( ) > {
978
+ // Create a shim which translates a Writer to a FormatWriter and saves
979
+ // off I/O errors. instead of discarding them
980
+ struct Adaptor < ' a , T > {
981
+ inner : & ' a mut T ,
982
+ error : IoResult < ( ) > ,
983
+ }
984
+ impl < ' a , T : Writer > fmt:: FormatWriter for Adaptor < ' a , T > {
985
+ fn write ( & mut self , bytes : & [ u8 ] ) -> fmt:: Result {
986
+ match self . inner . write ( bytes) {
987
+ Ok ( ( ) ) => Ok ( ( ) ) ,
988
+ Err ( e) => {
989
+ self . error = Err ( e) ;
990
+ Err ( fmt:: WriteError )
991
+ }
992
+ }
993
+ }
994
+ }
995
+
996
+ let mut output = Adaptor { inner : self , error : Ok ( ( ) ) } ;
997
+ match fmt:: write ( & mut output, fmt) {
998
+ Ok ( ( ) ) => Ok ( ( ) ) ,
999
+ Err ( ..) => output. error
1000
+ }
1001
+ }
1002
+
967
1003
/// Write a rust string into this sink.
968
1004
///
969
1005
/// The bytes written will be the UTF-8 encoded version of the input string.
You can’t perform that action at this time.
0 commit comments