@@ -15,6 +15,7 @@ use cast::{forget, transmute};
15
15
use clone:: Clone ;
16
16
use cmp:: { Eq , Ordering , TotalEq , TotalOrd } ;
17
17
use container:: Container ;
18
+ use default:: Default ;
18
19
use iter:: { DoubleEndedIterator , FromIterator , Iterator } ;
19
20
use libc:: { free, c_void} ;
20
21
use mem:: { size_of, move_val_init} ;
@@ -26,7 +27,8 @@ use ptr::RawPtr;
26
27
use ptr;
27
28
use rt:: global_heap:: { malloc_raw, realloc_raw} ;
28
29
use raw:: Slice ;
29
- use vec:: { ImmutableVector , Items , MutItems , MutableVector , RevItems } ;
30
+ use vec:: { ImmutableEqVector , ImmutableVector , Items , MutItems , MutableVector } ;
31
+ use vec:: { RevItems } ;
30
32
31
33
pub struct Vec < T > {
32
34
priv len: uint ,
@@ -340,6 +342,18 @@ impl<T> Vec<T> {
340
342
pub fn slice_from < ' a > ( & ' a self , start : uint ) -> & ' a [ T ] {
341
343
self . as_slice ( ) . slice_from ( start)
342
344
}
345
+
346
+ #[ inline]
347
+ pub fn init < ' a > ( & ' a self ) -> & ' a [ T ] {
348
+ self . slice ( 0 , self . len ( ) - 1 )
349
+ }
350
+ }
351
+
352
+ impl < T : Eq > Vec < T > {
353
+ /// Return true if a vector contains an element with the given value
354
+ pub fn contains ( & self , x : & T ) -> bool {
355
+ self . as_slice ( ) . contains ( x)
356
+ }
343
357
}
344
358
345
359
#[ inline]
@@ -348,6 +362,14 @@ pub fn append<T:Clone>(mut first: Vec<T>, second: &[T]) -> Vec<T> {
348
362
first
349
363
}
350
364
365
+ /// Appends one element to the vector provided. The vector itself is then
366
+ /// returned for use again.
367
+ #[ inline]
368
+ pub fn append_one < T > ( mut lhs : Vec < T > , x : T ) -> Vec < T > {
369
+ lhs. push ( x) ;
370
+ lhs
371
+ }
372
+
351
373
#[ unsafe_destructor]
352
374
impl < T > Drop for Vec < T > {
353
375
fn drop ( & mut self ) {
@@ -360,6 +382,12 @@ impl<T> Drop for Vec<T> {
360
382
}
361
383
}
362
384
385
+ impl < T > Default for Vec < T > {
386
+ fn default ( ) -> Vec < T > {
387
+ Vec :: new ( )
388
+ }
389
+ }
390
+
363
391
pub struct MoveItems < T > {
364
392
priv allocation : * mut c_void , // the block of memory allocated for the vector
365
393
priv iter : Items < ' static , T >
0 commit comments