diff options
Diffstat (limited to 'src/libstd/fmt/mod.rs')
| -rw-r--r-- | src/libstd/fmt/mod.rs | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/libstd/fmt/mod.rs b/src/libstd/fmt/mod.rs index f4f4be7172c..8e4d8707cca 100644 --- a/src/libstd/fmt/mod.rs +++ b/src/libstd/fmt/mod.rs @@ -34,12 +34,12 @@ arguments directly while performing minimal allocations. Some examples of the `format!` extension are: ```rust -format!("Hello"); // => ~"Hello" -format!("Hello, {:s}!", "world"); // => ~"Hello, world!" -format!("The number is {:d}", 1); // => ~"The number is 1" -format!("{:?}", ~[3, 4]); // => ~"~[3, 4]" -format!("{value}", value=4); // => ~"4" -format!("{} {}", 1, 2); // => ~"1 2" +format!("Hello"); // => "Hello".to_owned() +format!("Hello, {:s}!", "world"); // => "Hello, world!".to_owned() +format!("The number is {:d}", 1); // => "The number is 1".to_owned() +format!("{:?}", ~[3, 4]); // => "~[3, 4]".to_owned() +format!("{value}", value=4); // => "4".to_owned() +format!("{} {}", 1, 2); // => "1 2".to_owned() ``` From these, you can see that the first argument is a format string. It is @@ -62,7 +62,7 @@ iterator over the argument. Each time a "next argument" specifier is seen, the iterator advances. This leads to behavior like this: ```rust -format!("{1} {} {0} {}", 1, 2); // => ~"2 1 1 2" +format!("{1} {} {0} {}", 1, 2); // => "2 1 1 2".to_owned() ``` The internal iterator over the argument has not been advanced by the time the @@ -89,9 +89,9 @@ identifier '=' expression For example, the following `format!` expressions all use named argument: ```rust -format!("{argument}", argument = "test"); // => ~"test" -format!("{name} {}", 1, name = 2); // => ~"2 1" -format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => ~"a 3 ()" +format!("{argument}", argument = "test"); // => "test".to_owned() +format!("{name} {}", 1, name = 2); // => "2 1".to_owned() +format!("{a:s} {c:d} {b:?}", a="a", b=(), c=3); // => "a 3 ()".to_owned() ``` It is illegal to put positional parameters (those without names) after arguments @@ -330,7 +330,7 @@ to reference the string value of the argument which was selected upon. As an example: ```rust -format!("{0, select, other{#}}", "hello"); // => ~"hello" +format!("{0, select, other{#}}", "hello"); // => "hello".to_owned() ``` This example is the equivalent of `{0:s}` essentially. @@ -771,7 +771,7 @@ pub unsafe fn write_unsafe(output: &mut io::Writer, /// use std::fmt; /// /// let s = format_args!(fmt::format, "Hello, {}!", "world"); -/// assert_eq!(s, ~"Hello, world!"); +/// assert_eq!(s, "Hello, world!".to_owned()); /// ``` pub fn format(args: &Arguments) -> ~str { unsafe { format_unsafe(args.fmt, args.args) } |
