File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
branches/try2/src/libcollections Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: f1bff592b1d3dff14459374af930ae3fee6253ce
8
+ refs/heads/try2: 9731c28e116943220b397d3131273344f0750913
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change 17
17
18
18
use core:: prelude:: * ;
19
19
20
+ use core:: fmt;
20
21
use core:: iter:: { Enumerate , FilterMap } ;
21
22
use core:: mem:: replace;
22
23
@@ -176,6 +177,18 @@ impl<V:Clone> SmallIntMap<V> {
176
177
}
177
178
}
178
179
180
+ impl < V : fmt:: Show > fmt:: Show for SmallIntMap < V > {
181
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
182
+ try!( write ! ( f, r"\{" ) ) ;
183
+
184
+ for ( i, ( k, v) ) in self . iter ( ) . enumerate ( ) {
185
+ if i != 0 { try!( write ! ( f, ", " ) ) ; }
186
+ try!( write ! ( f, "{}: {}" , k, * v) ) ;
187
+ }
188
+
189
+ write ! ( f, r"\}" )
190
+ }
191
+ }
179
192
180
193
macro_rules! iterator {
181
194
( impl $name: ident -> $elem: ty, $getter: ident) => {
@@ -461,6 +474,20 @@ mod test_map {
461
474
assert ! ( called) ;
462
475
m. insert ( 2 , box 1 ) ;
463
476
}
477
+
478
+ #[ test]
479
+ fn test_show ( ) {
480
+ let mut map = SmallIntMap :: new ( ) ;
481
+ let empty = SmallIntMap :: < int > :: new ( ) ;
482
+
483
+ map. insert ( 1 , 2 ) ;
484
+ map. insert ( 3 , 4 ) ;
485
+
486
+ let map_str = map. to_str ( ) ;
487
+ let map_str = map_str. as_slice ( ) ;
488
+ assert ! ( map_str == "{1: 2, 3: 4}" || map_str == "{3: 4, 1: 2}" ) ;
489
+ assert_eq ! ( format!( "{}" , empty) , "{}" . to_string( ) ) ;
490
+ }
464
491
}
465
492
466
493
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments