Skip to content

Commit b6fbfc9

Browse files
committed
---
yaml --- r: 152365 b: refs/heads/try2 c: 9731c28 h: refs/heads/master i: 152363: 08bd44d v: v3
1 parent 6c6d1ea commit b6fbfc9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f1bff592b1d3dff14459374af930ae3fee6253ce
8+
refs/heads/try2: 9731c28e116943220b397d3131273344f0750913
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcollections/smallintmap.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use core::prelude::*;
1919

20+
use core::fmt;
2021
use core::iter::{Enumerate, FilterMap};
2122
use core::mem::replace;
2223

@@ -176,6 +177,18 @@ impl<V:Clone> SmallIntMap<V> {
176177
}
177178
}
178179

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+
}
179192

180193
macro_rules! iterator {
181194
(impl $name:ident -> $elem:ty, $getter:ident) => {
@@ -461,6 +474,20 @@ mod test_map {
461474
assert!(called);
462475
m.insert(2, box 1);
463476
}
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+
}
464491
}
465492

466493
#[cfg(test)]

0 commit comments

Comments
 (0)