Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/libstd/strbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use c_vec::CVec;
use cast;
use char::Char;
use container::Container;
use container::{Container, Mutable};
use fmt;
use io::Writer;
use iter::{Extendable, FromIterator, Iterator, range};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(), "");
}
}