1
- // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
134
134
//! * `E` ⇒ `UpperExp`
135
135
//!
136
136
//! What this means is that any type of argument which implements the
137
- //! `std:: fmt::Binary` trait can then be formatted with `{:b}`. Implementations
137
+ //! `fmt::Binary` trait can then be formatted with `{:b}`. Implementations
138
138
//! are provided for these traits for a number of primitive types by the
139
139
//! standard library as well. If no format is specified (as in `{}` or `{:6}`),
140
140
//! then the format trait used is the `Display` trait.
146
146
//! # use std::fmt;
147
147
//! # struct Foo; // our custom type
148
148
//! # impl fmt::Display for Foo {
149
- //! fn fmt(&self, f: &mut std:: fmt::Formatter) -> fmt::Result {
149
+ //! fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
150
150
//! # write!(f, "testing, testing")
151
151
//! # } }
152
152
//! ```
403
403
404
404
#![ unstable( feature = "std_misc" ) ]
405
405
406
- use string;
407
-
408
406
pub use core:: fmt:: { Formatter , Result , Writer , rt} ;
409
407
pub use core:: fmt:: { Show , String , Octal , Binary } ;
410
408
pub use core:: fmt:: { Display , Debug } ;
@@ -413,6 +411,8 @@ pub use core::fmt::{LowerExp, UpperExp};
413
411
pub use core:: fmt:: Error ;
414
412
pub use core:: fmt:: { ArgumentV1 , Arguments , write, radix, Radix , RadixFmt } ;
415
413
414
+ use string;
415
+
416
416
/// The format function takes a precompiled format string and a list of
417
417
/// arguments, to return the resulting formatted string.
418
418
///
@@ -434,3 +434,15 @@ pub fn format(args: Arguments) -> string::String {
434
434
let _ = write ! ( & mut output, "{}" , args) ;
435
435
output
436
436
}
437
+
438
+ #[ cfg( test) ]
439
+ mod tests {
440
+ use prelude:: * ;
441
+ use fmt;
442
+
443
+ #[ test]
444
+ fn test_format ( ) {
445
+ let s = fmt:: format ( format_args ! ( "Hello, {}!" , "world" ) ) ;
446
+ assert_eq ! ( s. as_slice( ) , "Hello, world!" ) ;
447
+ }
448
+ }
0 commit comments