File tree Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Expand file tree Collapse file tree 3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
5
5
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
6
6
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
7
7
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8
- refs/heads/try2: f1735cefcfdee5260ea6961cf785f545a340ff85
8
+ refs/heads/try2: 72fc4a5eb72b8ba96dba66400c7eecac93b0b252
9
9
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
10
10
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
11
11
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
Original file line number Diff line number Diff line change @@ -2385,7 +2385,7 @@ fn print_all<T: Printable>(printable_things: ~[T]) {
2385
2385
Declaring ` T ` as conforming to the ` Printable ` trait (as we earlier
2386
2386
did with ` Clone ` ) makes it possible to call methods from that trait
2387
2387
on values of type ` T ` inside the function. It will also cause a
2388
- compile-time error when anyone tries to call ` print_all ` on an array
2388
+ compile-time error when anyone tries to call ` print_all ` on a vector
2389
2389
whose element type does not have a ` Printable ` implementation.
2390
2390
2391
2391
Type parameters can have multiple bounds by separating them with ` + ` ,
@@ -2428,9 +2428,9 @@ fn draw_all<T: Drawable>(shapes: ~[T]) {
2428
2428
# draw_all(~[c]);
2429
2429
~~~~
2430
2430
2431
- You can call that on an array of circles, or an array of rectangles
2431
+ You can call that on a vector of circles, or a vector of rectangles
2432
2432
(assuming those have suitable ` Drawable ` traits defined), but not on
2433
- an array containing both circles and rectangles. When such behavior is
2433
+ a vector containing both circles and rectangles. When such behavior is
2434
2434
needed, a trait name can alternately be used as a type, called
2435
2435
an _ object_ .
2436
2436
Original file line number Diff line number Diff line change 12
12
13
13
use c_vec:: CVec ;
14
14
use char:: Char ;
15
- use container:: Container ;
15
+ use container:: { Container , Mutable } ;
16
16
use fmt;
17
17
use io:: Writer ;
18
18
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