@@ -63,17 +63,20 @@ println!("path exists: {}", path.exists());
63
63
64
64
*/
65
65
66
+ #![ deny( deprecated_owned_vector) ]
67
+
66
68
use container:: Container ;
67
69
use c_str:: CString ;
68
70
use clone:: Clone ;
69
71
use fmt;
70
72
use iter:: Iterator ;
71
73
use option:: { Option , None , Some } ;
72
74
use 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 } ;
76
78
use slice:: { ImmutableEqVector , ImmutableVector } ;
79
+ use vec:: Vec ;
77
80
78
81
/// Typedef for POSIX file paths.
79
82
/// See `posix::Path` for more info.
@@ -184,7 +187,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
184
187
fn as_vec < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
185
188
186
189
/// Converts the Path into an owned byte vector
187
- fn into_vec ( self ) -> ~ [ u8 ] ;
190
+ fn into_vec ( self ) -> Vec < u8 > ;
188
191
189
192
/// Returns an object that implements `Show` for printing paths
190
193
///
@@ -293,15 +296,15 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
293
296
let extlen = extension. container_as_bytes ( ) . len ( ) ;
294
297
match ( name. rposition_elem ( & dot) , extlen) {
295
298
( 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) ) ) ,
297
300
( idx, extlen) => {
298
301
let idx = match idx {
299
302
None | Some ( 0 ) => name. len ( ) ,
300
303
Some ( val) => val
301
304
} ;
302
305
303
306
let mut v;
304
- v = slice :: with_capacity ( idx + extlen + 1 ) ;
307
+ v = Vec :: with_capacity ( idx + extlen + 1 ) ;
305
308
v. push_all ( name. slice_to ( idx) ) ;
306
309
v. push ( dot) ;
307
310
v. push_all ( extension. container_as_bytes ( ) ) ;
@@ -441,10 +444,10 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
441
444
pub trait BytesContainer {
442
445
/// Returns a &[u8] representing the receiver
443
446
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>
445
448
#[ 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 ( ) )
448
451
}
449
452
/// Returns the receiver interpreted as a utf-8 string, if possible
450
453
#[ inline]
@@ -522,15 +525,27 @@ impl BytesContainer for ~str {
522
525
self . as_bytes ( )
523
526
}
524
527
#[ 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 > {
526
541
self . into_bytes ( )
527
542
}
528
543
#[ inline]
529
544
fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
530
545
Some ( self . as_slice ( ) )
531
546
}
532
547
#[ inline]
533
- fn is_str ( _: Option < ~ str > ) -> bool { true }
548
+ fn is_str ( _: Option < StrBuf > ) -> bool { true }
534
549
}
535
550
536
551
impl < ' a > BytesContainer for & ' a [ u8 ] {
@@ -545,8 +560,15 @@ impl BytesContainer for ~[u8] {
545
560
fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
546
561
self . as_slice ( )
547
562
}
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
+ }
548
570
#[ inline]
549
- fn container_into_owned_bytes ( self ) -> ~ [ u8 ] {
571
+ fn container_into_owned_bytes ( self ) -> Vec < u8 > {
550
572
self
551
573
}
552
574
}
@@ -564,10 +586,6 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
564
586
self . as_slice ( ) . as_bytes ( )
565
587
}
566
588
#[ inline]
567
- fn container_into_owned_bytes ( self ) -> ~[ u8 ] {
568
- self . into_owned ( ) . into_bytes ( )
569
- }
570
- #[ inline]
571
589
fn container_as_str < ' b > ( & ' b self ) -> Option < & ' b str > {
572
590
Some ( self . as_slice ( ) )
573
591
}
0 commit comments