Skip to content

Commit b40c3e9

Browse files
committed
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.
2 parents f483aa3 + a40b971 commit b40c3e9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/libstd/strbuf.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use c_vec::CVec;
1414
use char::Char;
15-
use container::Container;
15+
use container::{Container, Mutable};
1616
use fmt;
1717
use io::Writer;
1818
use iter::{Extendable, FromIterator, Iterator, range};
@@ -245,6 +245,13 @@ impl Container for StrBuf {
245245
}
246246
}
247247

248+
impl Mutable for StrBuf {
249+
#[inline]
250+
fn clear(&mut self) {
251+
self.vec.clear()
252+
}
253+
}
254+
248255
impl FromIterator<char> for StrBuf {
249256
fn from_iter<I:Iterator<char>>(iterator: I) -> StrBuf {
250257
let mut buf = StrBuf::new();
@@ -298,6 +305,7 @@ impl<H:Writer> ::hash::Hash<H> for StrBuf {
298305
#[cfg(test)]
299306
mod tests {
300307
extern crate test;
308+
use container::{Container, Mutable};
301309
use self::test::Bencher;
302310
use str::{Str, StrSlice};
303311
use super::StrBuf;
@@ -380,4 +388,12 @@ mod tests {
380388
let mut s = StrBuf::from_str("\u00FC"); // ü
381389
s.truncate(1);
382390
}
391+
392+
#[test]
393+
fn test_str_clear() {
394+
let mut s = StrBuf::from_str("12345");
395+
s.clear();
396+
assert_eq!(s.len(), 0);
397+
assert_eq!(s.as_slice(), "");
398+
}
383399
}

0 commit comments

Comments
 (0)