@@ -63,17 +63,20 @@ println!("path exists: {}", path.exists());
6363
6464*/
6565
66+ #![ deny( deprecated_owned_vector) ]
67+
6668use container:: Container ;
6769use c_str:: CString ;
6870use clone:: Clone ;
6971use fmt;
7072use iter:: Iterator ;
7173use option:: { Option , None , Some } ;
7274use str;
73- use str:: { MaybeOwned , OwnedStr , Str , StrSlice , from_utf8_lossy} ;
74- use slice ;
75- use slice:: { CloneableVector , OwnedCloneableVector , OwnedVector , Vector } ;
75+ use str:: { MaybeOwned , Str , StrSlice , from_utf8_lossy} ;
76+ use strbuf :: StrBuf ;
77+ use slice:: { OwnedCloneableVector , OwnedVector , Vector } ;
7678use slice:: { ImmutableEqVector , ImmutableVector } ;
79+ use vec:: Vec ;
7780
7881/// Typedef for POSIX file paths.
7982/// See `posix::Path` for more info.
@@ -184,7 +187,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
184187 fn as_vec < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
185188
186189 /// Converts the Path into an owned byte vector
187- fn into_vec ( self ) -> ~ [ u8 ] ;
190+ fn into_vec ( self ) -> Vec < u8 > ;
188191
189192 /// Returns an object that implements `Show` for printing paths
190193 ///
@@ -293,15 +296,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
293296 let extlen = extension. container_as_bytes ( ) . len ( ) ;
294297 match ( name. rposition_elem ( & dot) , extlen) {
295298 ( None , 0 ) | ( Some ( 0 ) , 0 ) => None ,
296- ( Some ( idx) , 0 ) => Some ( name. slice_to ( idx) . to_owned ( ) ) ,
299+ ( Some ( idx) , 0 ) => Some ( Vec :: from_slice ( name. slice_to ( idx) ) ) ,
297300 ( idx, extlen) => {
298301 let idx = match idx {
299302 None | Some ( 0 ) => name. len ( ) ,
300303 Some ( val) => val
301304 } ;
302305
303306 let mut v;
304- v = slice :: with_capacity ( idx + extlen + 1 ) ;
307+ v = Vec :: with_capacity ( idx + extlen + 1 ) ;
305308 v. push_all ( name. slice_to ( idx) ) ;
306309 v. push ( dot) ;
307310 v. push_all ( extension. container_as_bytes ( ) ) ;
@@ -441,10 +444,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
441444pub trait BytesContainer {
442445 /// Returns a &[u8] representing the receiver
443446 fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
444- /// Consumes the receiver and converts it into ~[u8]
447+ /// Consumes the receiver and converts it into Vec<u8>
445448 #[ inline]
446- fn container_into_owned_bytes ( self ) -> ~ [ u8 ] {
447- self . container_as_bytes ( ) . to_owned ( )
449+ fn container_into_owned_bytes ( self ) -> Vec < u8 > {
450+ Vec :: from_slice ( self . container_as_bytes ( ) )
448451 }
449452 /// Returns the receiver interpreted as a utf-8 string, if possible
450453 #[ inline]
@@ -522,15 +525,27 @@ impl BytesContainer for ~str {
522525 self . as_bytes ( )
523526 }
524527 #[ inline]
525- fn container_into_owned_bytes ( self ) -> ~[ u8 ] {
528+ fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
529+ Some ( self . as_slice ( ) )
530+ }
531+ #[ inline]
532+ fn is_str ( _: Option < ~str > ) -> bool { true }
533+ }
534+ impl BytesContainer for StrBuf {
535+ #[ inline]
536+ fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
537+ self . as_bytes ( )
538+ }
539+ #[ inline]
540+ fn container_into_owned_bytes ( self ) -> Vec < u8 > {
526541 self . into_bytes ( )
527542 }
528543 #[ inline]
529544 fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
530545 Some ( self . as_slice ( ) )
531546 }
532547 #[ inline]
533- fn is_str ( _: Option < ~ str > ) -> bool { true }
548+ fn is_str ( _: Option < StrBuf > ) -> bool { true }
534549}
535550
536551impl < ' a > BytesContainer for & ' a [ u8 ] {
@@ -545,8 +560,15 @@ impl BytesContainer for ~[u8] {
545560 fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
546561 self . as_slice ( )
547562 }
563+ }
564+
565+ impl BytesContainer for Vec < u8 > {
566+ #[ inline]
567+ fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
568+ self . as_slice ( )
569+ }
548570 #[ inline]
549- fn container_into_owned_bytes ( self ) -> ~ [ u8 ] {
571+ fn container_into_owned_bytes ( self ) -> Vec < u8 > {
550572 self
551573 }
552574}
@@ -564,10 +586,6 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
564586 self . as_slice ( ) . as_bytes ( )
565587 }
566588 #[ inline]
567- fn container_into_owned_bytes ( self ) -> ~[ u8 ] {
568- self . into_owned ( ) . into_bytes ( )
569- }
570- #[ inline]
571589 fn container_as_str < ' b > ( & ' b self ) -> Option < & ' b str > {
572590 Some ( self . as_slice ( ) )
573591 }
0 commit comments