File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 13
13
use c_vec:: CVec ;
14
14
use cast;
15
15
use char:: Char ;
16
- use container:: Container ;
16
+ use container:: { Container , Mutable } ;
17
17
use fmt;
18
18
use io:: Writer ;
19
19
use iter:: { Extendable , FromIterator , Iterator , range} ;
@@ -245,6 +245,13 @@ impl Container for StrBuf {
245
245
}
246
246
}
247
247
248
+ impl Mutable for StrBuf {
249
+ #[ inline]
250
+ fn clear ( & mut self ) {
251
+ self . vec . clear ( )
252
+ }
253
+ }
254
+
248
255
impl FromIterator < char > for StrBuf {
249
256
fn from_iter < I : Iterator < char > > ( iterator : I ) -> StrBuf {
250
257
let mut buf = StrBuf :: new ( ) ;
@@ -298,6 +305,7 @@ impl<H:Writer> ::hash::Hash<H> for StrBuf {
298
305
#[ cfg( test) ]
299
306
mod tests {
300
307
extern crate test;
308
+ use container:: { Container , Mutable } ;
301
309
use self :: test:: Bencher ;
302
310
use str:: { Str , StrSlice } ;
303
311
use super :: StrBuf ;
@@ -380,4 +388,12 @@ mod tests {
380
388
let mut s = StrBuf :: from_str ( "\u00FC " ) ; // ü
381
389
s. truncate ( 1 ) ;
382
390
}
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
+ }
383
399
}
You can’t perform that action at this time.
0 commit comments