1- // Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
1+ // Copyright 2013-2015 The Rust Project Developers. See the COPYRIGHT
22// file at the top-level directory of this distribution and at
33// http://rust-lang.org/COPYRIGHT.
44//
134134//! * `E` ⇒ `UpperExp`
135135//!
136136//! 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
138138//! are provided for these traits for a number of primitive types by the
139139//! standard library as well. If no format is specified (as in `{}` or `{:6}`),
140140//! then the format trait used is the `Display` trait.
146146//! # use std::fmt;
147147//! # struct Foo; // our custom type
148148//! # 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 {
150150//! # write!(f, "testing, testing")
151151//! # } }
152152//! ```
403403
404404#![ unstable( feature = "std_misc" ) ]
405405
406- use string;
407-
408406pub use core:: fmt:: { Formatter , Result , Writer , rt} ;
409407pub use core:: fmt:: { Show , String , Octal , Binary } ;
410408pub use core:: fmt:: { Display , Debug } ;
@@ -413,6 +411,8 @@ pub use core::fmt::{LowerExp, UpperExp};
413411pub use core:: fmt:: Error ;
414412pub use core:: fmt:: { ArgumentV1 , Arguments , write, radix, Radix , RadixFmt } ;
415413
414+ use string;
415+
416416/// The format function takes a precompiled format string and a list of
417417/// arguments, to return the resulting formatted string.
418418///
@@ -434,3 +434,15 @@ pub fn format(args: Arguments) -> string::String {
434434 let _ = write ! ( & mut output, "{}" , args) ;
435435 output
436436}
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