Skip to content

Implement Mutable trait for StrBuf #14110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2014
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(), "");
}
}