diff options
| author | Samuel Chase <samebchase@gmail.com> | 2013-05-11 19:18:14 +0530 |
|---|---|---|
| committer | Samuel Chase <samebchase@gmail.com> | 2013-05-11 19:18:14 +0530 |
| commit | e2c73ccaf22ec3908cf77e604233c5833ac5ae7d (patch) | |
| tree | 5329b77d008962906b4c65bf84ea18cc503bd824 | |
| parent | b8d0ebe124a574a55d9df7daf2b704802443aa2c (diff) | |
| download | rust-e2c73ccaf22ec3908cf77e604233c5833ac5ae7d.tar.gz rust-e2c73ccaf22ec3908cf77e604233c5833ac5ae7d.zip | |
Add str representation for HashSet.
| -rw-r--r-- | src/libcore/to_str.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libcore/to_str.rs b/src/libcore/to_str.rs index 3806335e240..299ba45986e 100644 --- a/src/libcore/to_str.rs +++ b/src/libcore/to_str.rs @@ -72,6 +72,24 @@ impl<A:ToStr+Hash+Eq, B:ToStr+Hash+Eq> ToStr for HashMap<A, B> { } } +impl<A:ToStr+Hash+Eq> ToStr for HashSet<A> { + #[inline(always)] + fn to_str(&self) -> ~str { + let mut acc = ~"{", first = true; + for self.each |element| { + if first { + first = false; + } + else { + acc.push_str(", "); + } + acc.push_str(element.to_str()); + } + acc.push_char('}'); + acc + } +} + impl<A:ToStr,B:ToStr> ToStr for (A, B) { #[inline(always)] fn to_str(&self) -> ~str { |
