File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1313use c_vec:: CVec ;
1414use cast;
1515use char:: Char ;
16- use container:: Container ;
16+ use container:: { Container , Mutable } ;
1717use fmt;
1818use io:: Writer ;
1919use 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+
248255impl 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) ]
299306mod 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}
You can’t perform that action at this time.
0 commit comments