1212
1313#![ allow( unused_variables) ]
1414
15- pub use self :: FormatError :: * ;
16-
1715use any;
1816use cell:: { Cell , Ref , RefMut } ;
1917use iter:: { Iterator , range} ;
@@ -23,10 +21,9 @@ use option::{Option, Some, None};
2321use ops:: Deref ;
2422use result:: { Ok , Err } ;
2523use result;
26- use slice:: { AsSlice , SlicePrelude } ;
24+ use slice:: SlicePrelude ;
2725use slice;
2826use str:: StrPrelude ;
29- use str;
3027
3128pub use self :: num:: radix;
3229pub use self :: num:: Radix ;
@@ -36,18 +33,16 @@ mod num;
3633mod float;
3734pub mod rt;
3835
39- pub type Result = result:: Result < ( ) , FormatError > ;
36+ #[ experimental = "core and I/O reconciliation may alter this definition" ]
37+ pub type Result = result:: Result < ( ) , Error > ;
4038
4139/// The error type which is returned from formatting a message into a stream.
4240///
4341/// This type does not support transmission of an error other than that an error
4442/// occurred. Any extra information must be arranged to be transmitted through
4543/// some other means.
46- pub enum FormatError {
47- /// A generic write error occurred during formatting, no other information
48- /// is transmitted via this variant.
49- WriteError ,
50- }
44+ #[ experimental = "core and I/O reconciliation may alter this definition" ]
45+ pub struct Error ;
5146
5247/// A collection of methods that are required to format a message into a stream.
5348///
@@ -58,6 +53,7 @@ pub enum FormatError {
5853/// This trait should generally not be implemented by consumers of the standard
5954/// library. The `write!` macro accepts an instance of `io::Writer`, and the
6055/// `io::Writer` trait is favored over implementing this trait.
56+ #[ experimental = "waiting for core and I/O reconciliation" ]
6157pub trait FormatWriter {
6258 /// Writes a slice of bytes into this writer, returning whether the write
6359 /// succeeded.
@@ -81,17 +77,13 @@ pub trait FormatWriter {
8177/// A struct to represent both where to emit formatting strings to and how they
8278/// should be formatted. A mutable version of this is passed to all formatting
8379/// traits.
80+ #[ unstable = "name may change and implemented traits are also unstable" ]
8481pub struct Formatter < ' a > {
85- /// Flags for formatting (packed version of rt::Flag)
86- pub flags : uint ,
87- /// Character used as 'fill' whenever there is alignment
88- pub fill : char ,
89- /// Boolean indication of whether the output should be left-aligned
90- pub align : rt:: Alignment ,
91- /// Optionally specified integer width that the output should be
92- pub width : Option < uint > ,
93- /// Optionally specified precision for numeric types
94- pub precision : Option < uint > ,
82+ flags : uint ,
83+ fill : char ,
84+ align : rt:: Alignment ,
85+ width : Option < uint > ,
86+ precision : Option < uint > ,
9587
9688 buf : & ' a mut FormatWriter +' a ,
9789 curarg : slice:: Items < ' a , Argument < ' a > > ,
@@ -104,6 +96,7 @@ enum Void {}
10496/// family of functions. It contains a function to format the given value. At
10597/// compile time it is ensured that the function and the value have the correct
10698/// types, and then this struct is used to canonicalize arguments to one type.
99+ #[ experimental = "implementation detail of the `format_args!` macro" ]
107100pub struct Argument < ' a > {
108101 formatter : extern "Rust" fn ( & Void , & mut Formatter ) -> Result ,
109102 value : & ' a Void ,
@@ -115,6 +108,7 @@ impl<'a> Arguments<'a> {
115108 /// which is valid because the compiler performs all necessary validation to
116109 /// ensure that the resulting call to format/write would be safe.
117110 #[ doc( hidden) ] #[ inline]
111+ #[ experimental = "implementation detail of the `format_args!` macro" ]
118112 pub unsafe fn new < ' a > ( pieces : & ' static [ & ' static str ] ,
119113 args : & ' a [ Argument < ' a > ] ) -> Arguments < ' a > {
120114 Arguments {
@@ -128,6 +122,7 @@ impl<'a> Arguments<'a> {
128122 /// The `pieces` array must be at least as long as `fmt` to construct
129123 /// a valid Arguments structure.
130124 #[ doc( hidden) ] #[ inline]
125+ #[ experimental = "implementation detail of the `format_args!` macro" ]
131126 pub unsafe fn with_placeholders < ' a > ( pieces : & ' static [ & ' static str ] ,
132127 fmt : & ' static [ rt:: Argument < ' static > ] ,
133128 args : & ' a [ Argument < ' a > ] ) -> Arguments < ' a > {
@@ -148,6 +143,7 @@ impl<'a> Arguments<'a> {
148143/// and pass it to a function or closure, passed as the first argument. The
149144/// macro validates the format string at compile-time so usage of the `write`
150145/// and `format` functions can be safely performed.
146+ #[ stable]
151147pub struct Arguments < ' a > {
152148 // Format string pieces to print.
153149 pieces : & ' a [ & ' a str ] ,
@@ -169,84 +165,57 @@ impl<'a> Show for Arguments<'a> {
169165/// When a format is not otherwise specified, types are formatted by ascribing
170166/// to this trait. There is not an explicit way of selecting this trait to be
171167/// used for formatting, it is only if no other format is specified.
168+ #[ unstable = "I/O and core have yet to be reconciled" ]
172169pub trait Show for Sized ? {
173170 /// Formats the value using the given formatter.
174171 fn fmt ( & self , & mut Formatter ) -> Result ;
175172}
176173
177- /// Format trait for the `b` character
178- pub trait Bool for Sized ? {
179- /// Formats the value using the given formatter.
180- fn fmt ( & self , & mut Formatter ) -> Result ;
181- }
182-
183- /// Format trait for the `c` character
184- pub trait Char for Sized ? {
185- /// Formats the value using the given formatter.
186- fn fmt ( & self , & mut Formatter ) -> Result ;
187- }
188-
189- /// Format trait for the `i` and `d` characters
190- pub trait Signed for Sized ? {
191- /// Formats the value using the given formatter.
192- fn fmt ( & self , & mut Formatter ) -> Result ;
193- }
194-
195- /// Format trait for the `u` character
196- pub trait Unsigned for Sized ? {
197- /// Formats the value using the given formatter.
198- fn fmt ( & self , & mut Formatter ) -> Result ;
199- }
200174
201175/// Format trait for the `o` character
176+ #[ unstable = "I/O and core have yet to be reconciled" ]
202177pub trait Octal for Sized ? {
203178 /// Formats the value using the given formatter.
204179 fn fmt ( & self , & mut Formatter ) -> Result ;
205180}
206181
207182/// Format trait for the `t` character
183+ #[ unstable = "I/O and core have yet to be reconciled" ]
208184pub trait Binary for Sized ? {
209185 /// Formats the value using the given formatter.
210186 fn fmt ( & self , & mut Formatter ) -> Result ;
211187}
212188
213189/// Format trait for the `x` character
190+ #[ unstable = "I/O and core have yet to be reconciled" ]
214191pub trait LowerHex for Sized ? {
215192 /// Formats the value using the given formatter.
216193 fn fmt ( & self , & mut Formatter ) -> Result ;
217194}
218195
219196/// Format trait for the `X` character
197+ #[ unstable = "I/O and core have yet to be reconciled" ]
220198pub trait UpperHex for Sized ? {
221199 /// Formats the value using the given formatter.
222200 fn fmt ( & self , & mut Formatter ) -> Result ;
223201}
224202
225- /// Format trait for the `s` character
226- pub trait String for Sized ? {
227- /// Formats the value using the given formatter.
228- fn fmt ( & self , & mut Formatter ) -> Result ;
229- }
230-
231203/// Format trait for the `p` character
204+ #[ unstable = "I/O and core have yet to be reconciled" ]
232205pub trait Pointer for Sized ? {
233206 /// Formats the value using the given formatter.
234207 fn fmt ( & self , & mut Formatter ) -> Result ;
235208}
236209
237- /// Format trait for the `f` character
238- pub trait Float for Sized ? {
239- /// Formats the value using the given formatter.
240- fn fmt ( & self , & mut Formatter ) -> Result ;
241- }
242-
243210/// Format trait for the `e` character
211+ #[ unstable = "I/O and core have yet to be reconciled" ]
244212pub trait LowerExp for Sized ? {
245213 /// Formats the value using the given formatter.
246214 fn fmt ( & self , & mut Formatter ) -> Result ;
247215}
248216
249217/// Format trait for the `E` character
218+ #[ unstable = "I/O and core have yet to be reconciled" ]
250219pub trait UpperExp for Sized ? {
251220 /// Formats the value using the given formatter.
252221 fn fmt ( & self , & mut Formatter ) -> Result ;
@@ -271,6 +240,8 @@ static DEFAULT_ARGUMENT: rt::Argument<'static> = rt::Argument {
271240///
272241/// * output - the buffer to write output to
273242/// * args - the precompiled arguments generated by `format_args!`
243+ #[ experimental = "libcore and I/O have yet to be reconciled, and this is an \
244+ implementation detail which should not otherwise be exported"]
274245pub fn write ( output : & mut FormatWriter , args : & Arguments ) -> Result {
275246 let mut formatter = Formatter {
276247 flags : 0 ,
@@ -368,6 +339,7 @@ impl<'a> Formatter<'a> {
368339 ///
369340 /// This function will correctly account for the flags provided as well as
370341 /// the minimum width. It will not take precision into account.
342+ #[ unstable = "definition may change slightly over time" ]
371343 pub fn pad_integral ( & mut self ,
372344 is_positive : bool ,
373345 prefix : & str ,
@@ -440,6 +412,7 @@ impl<'a> Formatter<'a> {
440412 /// is longer than this length
441413 ///
442414 /// Notably this function ignored the `flag` parameters
415+ #[ unstable = "definition may change slightly over time" ]
443416 pub fn pad ( & mut self , s : & str ) -> Result {
444417 // Make sure there's a fast path up front
445418 if self . width . is_none ( ) && self . precision . is_none ( ) {
@@ -516,19 +489,48 @@ impl<'a> Formatter<'a> {
516489
517490 /// Writes some data to the underlying buffer contained within this
518491 /// formatter.
492+ #[ unstable = "reconciling core and I/O may alter this definition" ]
519493 pub fn write ( & mut self , data : & [ u8 ] ) -> Result {
520494 self . buf . write ( data)
521495 }
522496
523497 /// Writes some formatted information into this instance
498+ #[ unstable = "reconciling core and I/O may alter this definition" ]
524499 pub fn write_fmt ( & mut self , fmt : & Arguments ) -> Result {
525500 write ( self . buf , fmt)
526501 }
502+
503+ /// Flags for formatting (packed version of rt::Flag)
504+ #[ experimental = "return type may change and method was just created" ]
505+ pub fn flags ( & self ) -> uint { self . flags }
506+
507+ /// Character used as 'fill' whenever there is alignment
508+ #[ unstable = "method was just created" ]
509+ pub fn fill ( & self ) -> char { self . fill }
510+
511+ /// Flag indicating what form of alignment was requested
512+ #[ unstable = "method was just created" ]
513+ pub fn align ( & self ) -> rt:: Alignment { self . align }
514+
515+ /// Optionally specified integer width that the output should be
516+ #[ unstable = "method was just created" ]
517+ pub fn width ( & self ) -> Option < uint > { self . width }
518+
519+ /// Optionally specified precision for numeric types
520+ #[ unstable = "method was just created" ]
521+ pub fn precision ( & self ) -> Option < uint > { self . precision }
522+ }
523+
524+ impl Show for Error {
525+ fn fmt ( & self , f : & mut Formatter ) -> Result {
526+ "an error occurred when formatting an argument" . fmt ( f)
527+ }
527528}
528529
529530/// This is a function which calls are emitted to by the compiler itself to
530531/// create the Argument structures that are passed into the `format` function.
531532#[ doc( hidden) ] #[ inline]
533+ #[ experimental = "implementation detail of the `format_args!` macro" ]
532534pub fn argument < ' a , T > ( f : extern "Rust" fn ( & T , & mut Formatter ) -> Result ,
533535 t : & ' a T ) -> Argument < ' a > {
534536 unsafe {
@@ -542,15 +544,17 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
542544/// When the compiler determines that the type of an argument *must* be a string
543545/// (such as for select), then it invokes this method.
544546#[ doc( hidden) ] #[ inline]
547+ #[ experimental = "implementation detail of the `format_args!` macro" ]
545548pub fn argumentstr < ' a > ( s : & ' a & str ) -> Argument < ' a > {
546- argument ( String :: fmt, s)
549+ argument ( Show :: fmt, s)
547550}
548551
549552/// When the compiler determines that the type of an argument *must* be a uint
550553/// (such as for plural), then it invokes this method.
551554#[ doc( hidden) ] #[ inline]
555+ #[ experimental = "implementation detail of the `format_args!` macro" ]
552556pub fn argumentuint < ' a > ( s : & ' a uint ) -> Argument < ' a > {
553- argument ( Unsigned :: fmt, s)
557+ argument ( Show :: fmt, s)
554558}
555559
556560// Implementations of the core formatting traits
@@ -565,32 +569,26 @@ impl<'a> Show for &'a Show+'a {
565569 fn fmt ( & self , f : & mut Formatter ) -> Result { ( * self ) . fmt ( f) }
566570}
567571
568- impl Bool for bool {
569- fn fmt ( & self , f : & mut Formatter ) -> Result {
570- String :: fmt ( if * self { "true" } else { "false" } , f)
571- }
572- }
573-
574- impl < T : str:: Str > String for T {
572+ impl Show for bool {
575573 fn fmt ( & self , f : & mut Formatter ) -> Result {
576- f . pad ( self . as_slice ( ) )
574+ Show :: fmt ( if * self { "true" } else { "false" } , f )
577575 }
578576}
579577
580- impl String for str {
578+ impl Show for str {
581579 fn fmt ( & self , f : & mut Formatter ) -> Result {
582580 f. pad ( self )
583581 }
584582}
585583
586- impl Char for char {
584+ impl Show for char {
587585 fn fmt ( & self , f : & mut Formatter ) -> Result {
588586 use char:: Char ;
589587
590588 let mut utf8 = [ 0u8 , ..4 ] ;
591589 let amt = self . encode_utf8 ( & mut utf8) . unwrap_or ( 0 ) ;
592590 let s: & str = unsafe { mem:: transmute ( utf8[ ..amt] ) } ;
593- String :: fmt ( s, f)
591+ Show :: fmt ( s, f)
594592 }
595593}
596594
@@ -620,7 +618,7 @@ impl<'a, T> Pointer for &'a mut T {
620618}
621619
622620macro_rules! floating( ( $ty: ident) => {
623- impl Float for $ty {
621+ impl Show for $ty {
624622 fn fmt( & self , fmt: & mut Formatter ) -> Result {
625623 use num:: Float ;
626624
@@ -688,19 +686,6 @@ floating!(f64)
688686
689687// Implementation of Show for various core types
690688
691- macro_rules! delegate( ( $ty: ty to $other: ident) => {
692- impl Show for $ty {
693- fn fmt( & self , f: & mut Formatter ) -> Result {
694- $other:: fmt( self , f)
695- }
696- }
697- } )
698- delegate ! ( str to String )
699- delegate ! ( bool to Bool )
700- delegate ! ( char to Char )
701- delegate ! ( f32 to Float )
702- delegate ! ( f64 to Float )
703-
704689impl < T > Show for * const T {
705690 fn fmt ( & self , f : & mut Formatter ) -> Result { Pointer :: fmt ( self , f) }
706691}
0 commit comments