Skip to content

Commit 9426bad

Browse files
committed
---
yaml --- r: 46581 b: refs/heads/auto c: c2be2ec h: refs/heads/master i: 46579: 673f825 v: v3
1 parent c59e392 commit 9426bad

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 061a2237230d3abcdb30ecb8987e5de17e67a58e
17+
refs/heads/auto: c2be2ec42df4381ad805d81ff964215c3ce414b3

branches/auto/src/libcore/to_str.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,53 @@ impl<A:ToStr,B:ToStr,C:ToStr> ToStr for (A, B, C) {
7474
}
7575
}
7676

77+
impl<A:ToStr> ToStr for &[A] {
78+
#[inline(always)]
79+
pure fn to_str(&self) -> ~str {
80+
unsafe {
81+
// FIXME #4568
82+
// Bleh -- not really unsafe
83+
// push_str and push_char
84+
let mut acc = ~"[", first = true;
85+
for self.each |elt| {
86+
unsafe {
87+
if first { first = false; }
88+
else { str::push_str(&mut acc, ~", "); }
89+
str::push_str(&mut acc, elt.to_str());
90+
}
91+
}
92+
str::push_char(&mut acc, ']');
93+
acc
94+
}
95+
}
96+
}
97+
7798
impl<A:ToStr> ToStr for ~[A] {
7899
#[inline(always)]
79100
pure fn to_str(&self) -> ~str {
80101
unsafe {
102+
// FIXME #4568
103+
// Bleh -- not really unsafe
104+
// push_str and push_char
105+
let mut acc = ~"[", first = true;
106+
for self.each |elt| {
107+
unsafe {
108+
if first { first = false; }
109+
else { str::push_str(&mut acc, ~", "); }
110+
str::push_str(&mut acc, elt.to_str());
111+
}
112+
}
113+
str::push_char(&mut acc, ']');
114+
acc
115+
}
116+
}
117+
}
118+
119+
impl<A:ToStr> ToStr for @[A] {
120+
#[inline(always)]
121+
pure fn to_str(&self) -> ~str {
122+
unsafe {
123+
// FIXME #4568
81124
// Bleh -- not really unsafe
82125
// push_str and push_char
83126
let mut acc = ~"[", first = true;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
assert (~[0, 1]).to_str() == ~"[0, 1]";
13+
assert (&[1, 2]).to_str() == ~"[1, 2]";
14+
assert (@[2, 3]).to_str() == ~"[2, 3]";
15+
16+
let foo = ~[3, 4];
17+
let bar = &[4, 5];
18+
let baz = @[5, 6];
19+
20+
assert foo.to_str() == ~"[3, 4]";
21+
assert bar.to_str() == ~"[4, 5]";
22+
assert baz.to_str() == ~"[5, 6]";
23+
24+
}

0 commit comments

Comments
 (0)