Skip to content

Commit e2c73cc

Browse files
committed
Add str representation for HashSet.
1 parent b8d0ebe commit e2c73cc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libcore/to_str.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> {
7272
}
7373
}
7474
75+
impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> {
76+
#[inline(always)]
77+
fn to_str(&self) -> ~str {
78+
let mut acc = ~"{", first = true;
79+
for self.each |element| {
80+
if first {
81+
first = false;
82+
}
83+
else {
84+
acc.push_str(", ");
85+
}
86+
acc.push_str(element.to_str());
87+
}
88+
acc.push_char('}');
89+
acc
90+
}
91+
}
92+
7593
impl<A:ToStr,B:ToStr> ToStr for (A, B) {
7694
#[inline(always)]
7795
fn to_str(&self) -> ~str {

0 commit comments

Comments
 (0)