diff options
| author | bors <bors@rust-lang.org> | 2014-05-11 16:21:44 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-05-11 16:21:44 -0700 |
| commit | b40c3e9d3dd0a6be4d048389d33435f82205d376 (patch) | |
| tree | 628a8cabc5247137d635ad926695878d98e71183 /src/libstd | |
| parent | f483aa3a91ff9baf290ddf22209b984ec1f74b0c (diff) | |
| parent | a40b971aaf64f9ba189ac07eebf1890d995ae2dc (diff) | |
| download | rust-b40c3e9d3dd0a6be4d048389d33435f82205d376.tar.gz rust-b40c3e9d3dd0a6be4d048389d33435f82205d376.zip | |
auto merge of #14110 : SSheldon/rust/strbuf_mutable, r=alexcrichton
Despite implementing the Container trait, StrBuf did not implement the Mutable trait and had no clear method; this request implements the clear method of the Mutable trait for StrBuf. Testing done: added a test and ran `make check` without any failures.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/strbuf.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/libstd/strbuf.rs b/src/libstd/strbuf.rs index 45ab690b0a2..75008745cf3 100644 --- a/src/libstd/strbuf.rs +++ b/src/libstd/strbuf.rs @@ -12,7 +12,7 @@ use c_vec::CVec; use char::Char; -use container::Container; +use container::{Container, Mutable}; use fmt; use io::Writer; use iter::{Extendable, FromIterator, Iterator, range}; @@ -245,6 +245,13 @@ impl Container for StrBuf { } } +impl Mutable for StrBuf { + #[inline] + fn clear(&mut self) { + self.vec.clear() + } +} + impl FromIterator<char> for StrBuf { fn from_iter<I:Iterator<char>>(iterator: I) -> StrBuf { let mut buf = StrBuf::new(); @@ -298,6 +305,7 @@ impl<H:Writer> ::hash::Hash<H> for StrBuf { #[cfg(test)] mod tests { extern crate test; + use container::{Container, Mutable}; use self::test::Bencher; use str::{Str, StrSlice}; use super::StrBuf; @@ -380,4 +388,12 @@ mod tests { let mut s = StrBuf::from_str("\u00FC"); // ΓΌ s.truncate(1); } + + #[test] + fn test_str_clear() { + let mut s = StrBuf::from_str("12345"); + s.clear(); + assert_eq!(s.len(), 0); + assert_eq!(s.as_slice(), ""); + } } |
