Implement Mutable trait for StrBuf.

This commit is contained in:
Steven Sheldon 2014-05-11 03:49:09 -07:00
parent adb8b0b230
commit a40b971aaf

View File

@ -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};
@ -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(), "");
}
}