@@ -23,7 +23,7 @@ use char::Char;
23
23
use clone:: Clone ;
24
24
use container:: { Container , Mutable } ;
25
25
use iter:: Times ;
26
- use iterator:: { Iterator , IteratorUtil , FilterIterator , AdditiveIterator , MapIterator } ;
26
+ use iterator:: { Iterator , FromIterator , IteratorUtil , FilterIterator , AdditiveIterator , MapIterator } ;
27
27
use libc;
28
28
use num:: Zero ;
29
29
use option:: { None , Option , Some } ;
@@ -2319,6 +2319,18 @@ impl<'self> Iterator<u8> for BytesRevIterator<'self> {
2319
2319
}
2320
2320
}
2321
2321
2322
+ impl<T: Iterator<char>> FromIterator<char, T> for ~str {
2323
+ #[inline]
2324
+ fn from_iterator(iterator: &mut T) -> ~str {
2325
+ let (lower, _) = iterator.size_hint();
2326
+ let mut buf = with_capacity(lower);
2327
+ for iterator.advance |ch| {
2328
+ buf.push_char(ch)
2329
+ }
2330
+ buf
2331
+ }
2332
+ }
2333
+
2322
2334
// This works because every lifetime is a sub-lifetime of 'static
2323
2335
impl<'self> Zero for &'self str {
2324
2336
fn zero() -> &'self str { " " }
@@ -2482,6 +2494,16 @@ mod tests {
2482
2494
assert_eq!(~" 华ประเทศไทย中", data);
2483
2495
}
2484
2496
2497
+ #[test]
2498
+ fn test_collect() {
2499
+ let empty = " ";
2500
+ let s: ~str = empty.iter().collect();
2501
+ assert_eq!(empty, s.as_slice());
2502
+ let data = " ประเทศไทย中";
2503
+ let s: ~str = data.iter().collect();
2504
+ assert_eq!(data, s.as_slice());
2505
+ }
2506
+
2485
2507
#[test]
2486
2508
fn test_clear() {
2487
2509
let mut empty = ~" ";
0 commit comments