@@ -15,6 +15,7 @@ use cast::{forget, transmute};
1515use clone:: Clone ;
1616use cmp:: { Eq , Ordering , TotalEq , TotalOrd } ;
1717use container:: Container ;
18+ use default:: Default ;
1819use iter:: { DoubleEndedIterator , FromIterator , Iterator } ;
1920use libc:: { free, c_void} ;
2021use mem:: { size_of, move_val_init} ;
@@ -26,7 +27,8 @@ use ptr::RawPtr;
2627use ptr;
2728use rt:: global_heap:: { malloc_raw, realloc_raw} ;
2829use raw:: Slice ;
29- use vec:: { ImmutableVector , Items , MutItems , MutableVector , RevItems } ;
30+ use vec:: { ImmutableEqVector , ImmutableVector , Items , MutItems , MutableVector } ;
31+ use vec:: { RevItems } ;
3032
3133pub struct Vec < T > {
3234 priv len: uint ,
@@ -340,6 +342,18 @@ impl<T> Vec<T> {
340342 pub fn slice_from < ' a > ( & ' a self , start : uint ) -> & ' a [ T ] {
341343 self . as_slice ( ) . slice_from ( start)
342344 }
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+ }
343357}
344358
345359#[ inline]
@@ -348,6 +362,14 @@ pub fn append<T:Clone>(mut first: Vec<T>, second: &[T]) -> Vec<T> {
348362 first
349363}
350364
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+
351373#[ unsafe_destructor]
352374impl < T > Drop for Vec < T > {
353375 fn drop ( & mut self ) {
@@ -360,6 +382,12 @@ impl<T> Drop for Vec<T> {
360382 }
361383}
362384
385+ impl < T > Default for Vec < T > {
386+ fn default ( ) -> Vec < T > {
387+ Vec :: new ( )
388+ }
389+ }
390+
363391pub struct MoveItems < T > {
364392 priv allocation : * mut c_void , // the block of memory allocated for the vector
365393 priv iter : Items < ' static , T >
0 commit comments