@@ -70,6 +70,16 @@ pub trait FormatWriter {
7070 /// This function will return an instance of `FormatError` on error.
7171 fn write ( & mut self , bytes : & [ u8 ] ) -> Result ;
7272
73+ // NOTE(stage0): Remove cfg after a snapshot
74+ #[ cfg( not( stage0) ) ]
75+ /// Glue for usage of the `write!` macro with implementers of this trait.
76+ ///
77+ /// This method should generally not be invoked manually, but rather through
78+ /// the `write!` macro itself.
79+ fn write_fmt ( & mut self , args : Arguments ) -> Result { write ( self , args) }
80+
81+ // NOTE(stage0): Remove method after a snapshot
82+ #[ cfg( stage0) ]
7383 /// Glue for usage of the `write!` macro with implementers of this trait.
7484 ///
7585 /// This method should generally not be invoked manually, but rather through
@@ -180,6 +190,7 @@ impl<'a> Arguments<'a> {
180190/// macro validates the format string at compile-time so usage of the `write`
181191/// and `format` functions can be safely performed.
182192#[ stable]
193+ #[ deriving( Copy ) ]
183194pub struct Arguments < ' a > {
184195 // Format string pieces to print.
185196 pieces : & ' a [ & ' a str ] ,
@@ -193,6 +204,14 @@ pub struct Arguments<'a> {
193204}
194205
195206impl < ' a > Show for Arguments < ' a > {
207+ // NOTE(stage0): Remove cfg after a snapshot
208+ #[ cfg( not( stage0) ) ]
209+ fn fmt ( & self , fmt : & mut Formatter ) -> Result {
210+ write ( fmt. buf , * self )
211+ }
212+
213+ // NOTE(stage0): Remove method after a snapshot
214+ #[ cfg( stage0) ]
196215 fn fmt ( & self , fmt : & mut Formatter ) -> Result {
197216 write ( fmt. buf , self )
198217 }
@@ -268,6 +287,63 @@ static DEFAULT_ARGUMENT: rt::Argument<'static> = rt::Argument {
268287 }
269288} ;
270289
290+ // NOTE(stage0): Remove cfg after a snapshot
291+ #[ cfg( not( stage0) ) ]
292+ /// The `write` function takes an output stream, a precompiled format string,
293+ /// and a list of arguments. The arguments will be formatted according to the
294+ /// specified format string into the output stream provided.
295+ ///
296+ /// # Arguments
297+ ///
298+ /// * output - the buffer to write output to
299+ /// * args - the precompiled arguments generated by `format_args!`
300+ #[ experimental = "libcore and I/O have yet to be reconciled, and this is an \
301+ implementation detail which should not otherwise be exported"]
302+ pub fn write ( output : & mut FormatWriter , args : Arguments ) -> Result {
303+ let mut formatter = Formatter {
304+ flags : 0 ,
305+ width : None ,
306+ precision : None ,
307+ buf : output,
308+ align : rt:: AlignUnknown ,
309+ fill : ' ' ,
310+ args : args. args ,
311+ curarg : args. args . iter ( ) ,
312+ } ;
313+
314+ let mut pieces = args. pieces . iter ( ) ;
315+
316+ match args. fmt {
317+ None => {
318+ // We can use default formatting parameters for all arguments.
319+ for _ in range ( 0 , args. args . len ( ) ) {
320+ try!( formatter. buf . write ( pieces. next ( ) . unwrap ( ) . as_bytes ( ) ) ) ;
321+ try!( formatter. run ( & DEFAULT_ARGUMENT ) ) ;
322+ }
323+ }
324+ Some ( fmt) => {
325+ // Every spec has a corresponding argument that is preceded by
326+ // a string piece.
327+ for ( arg, piece) in fmt. iter ( ) . zip ( pieces. by_ref ( ) ) {
328+ try!( formatter. buf . write ( piece. as_bytes ( ) ) ) ;
329+ try!( formatter. run ( arg) ) ;
330+ }
331+ }
332+ }
333+
334+ // There can be only one trailing string piece left.
335+ match pieces. next ( ) {
336+ Some ( piece) => {
337+ try!( formatter. buf . write ( piece. as_bytes ( ) ) ) ;
338+ }
339+ None => { }
340+ }
341+
342+ Ok ( ( ) )
343+ }
344+
345+ // NOTE(stage0): Remove function after a snapshot
346+ #[ cfg( stage0) ]
271347/// The `write` function takes an output stream, a precompiled format string,
272348/// and a list of arguments. The arguments will be formatted according to the
273349/// specified format string into the output stream provided.
@@ -527,6 +603,16 @@ impl<'a> Formatter<'a> {
527603 self . buf . write ( data)
528604 }
529605
606+ // NOTE(stage0): Remove cfg after a snapshot
607+ #[ cfg( not( stage0) ) ]
608+ /// Writes some formatted information into this instance
609+ #[ unstable = "reconciling core and I/O may alter this definition" ]
610+ pub fn write_fmt ( & mut self , fmt : Arguments ) -> Result {
611+ write ( self . buf , fmt)
612+ }
613+
614+ // NOTE(stage0): Remove method after a snapshot
615+ #[ cfg( stage0) ]
530616 /// Writes some formatted information into this instance
531617 #[ unstable = "reconciling core and I/O may alter this definition" ]
532618 pub fn write_fmt ( & mut self , fmt : & Arguments ) -> Result {
0 commit comments