mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 21:47:15 +03:00
Implement Mutable trait for StrBuf.
This commit is contained in:
+17
-1
@@ -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 @@ fn len(&self) -> uint {
|
||||
}
|
||||
}
|
||||
|
||||
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 @@ fn hash(&self, hasher: &mut H) {
|
||||
#[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 @@ fn test_str_truncate_split_codepoint() {
|
||||
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(), "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user