@@ -68,6 +68,7 @@ println!("path exists: {}", path.exists());
6868#![ experimental]
6969
7070use collections:: { Collection , MutableSeq } ;
71+ use core:: kinds:: Sized ;
7172use c_str:: CString ;
7273use clone:: Clone ;
7374use fmt;
@@ -627,7 +628,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
627628 /// ```
628629 #[ inline]
629630 fn push_many < T : BytesContainer > ( & mut self , paths : & [ T ] ) {
630- let t: Option < T > = None ;
631+ let t: Option < & T > = None ;
631632 if BytesContainer :: is_str ( t) {
632633 for p in paths. iter ( ) {
633634 self . push ( p. container_as_str ( ) . unwrap ( ) )
@@ -792,14 +793,9 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
792793}
793794
794795/// A trait that represents something bytes-like (e.g. a &[u8] or a &str)
795- pub trait BytesContainer {
796+ pub trait BytesContainer for Sized ? {
796797 /// Returns a &[u8] representing the receiver
797798 fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
798- /// Consumes the receiver and converts it into Vec<u8>
799- #[ inline]
800- fn container_into_owned_bytes ( self ) -> Vec < u8 > {
801- self . container_as_bytes ( ) . to_vec ( )
802- }
803799 /// Returns the receiver interpreted as a utf-8 string, if possible
804800 #[ inline]
805801 fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
@@ -808,7 +804,7 @@ pub trait BytesContainer {
808804 /// Returns whether .container_as_str() is guaranteed to not fail
809805 // FIXME (#8888): Remove unused arg once ::<for T> works
810806 #[ inline]
811- fn is_str ( _: Option < Self > ) -> bool { false }
807+ fn is_str ( _: Option < & Self > ) -> bool { false }
812808}
813809
814810/// A trait that represents the unsafe operations on GenericPaths
@@ -860,48 +856,44 @@ impl<'a, P: GenericPath> Display<'a, P> {
860856 }
861857}
862858
863- impl < ' a > BytesContainer for & ' a str {
859+ impl BytesContainer for str {
864860 #[ inline]
865- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
861+ fn container_as_bytes ( & self ) -> & [ u8 ] {
866862 self . as_bytes ( )
867863 }
868864 #[ inline]
869- fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
870- Some ( * self )
865+ fn container_as_str ( & self ) -> Option < & str > {
866+ Some ( self )
871867 }
872868 #[ inline]
873- fn is_str ( _: Option < & ' a str > ) -> bool { true }
869+ fn is_str ( _: Option < & str > ) -> bool { true }
874870}
875871
876872impl BytesContainer for String {
877873 #[ inline]
878- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
874+ fn container_as_bytes ( & self ) -> & [ u8 ] {
879875 self . as_bytes ( )
880876 }
881877 #[ inline]
882- fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
878+ fn container_as_str ( & self ) -> Option < & str > {
883879 Some ( self . as_slice ( ) )
884880 }
885881 #[ inline]
886- fn is_str ( _: Option < String > ) -> bool { true }
882+ fn is_str ( _: Option < & String > ) -> bool { true }
887883}
888884
889- impl < ' a > BytesContainer for & ' a [ u8 ] {
885+ impl BytesContainer for [ u8 ] {
890886 #[ inline]
891- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
892- * self
887+ fn container_as_bytes ( & self ) -> & [ u8 ] {
888+ self
893889 }
894890}
895891
896892impl BytesContainer for Vec < u8 > {
897893 #[ inline]
898- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
894+ fn container_as_bytes ( & self ) -> & [ u8 ] {
899895 self . as_slice ( )
900896 }
901- #[ inline]
902- fn container_into_owned_bytes ( self ) -> Vec < u8 > {
903- self
904- }
905897}
906898
907899impl BytesContainer for CString {
@@ -921,7 +913,20 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
921913 Some ( self . as_slice ( ) )
922914 }
923915 #[ inline]
924- fn is_str ( _: Option < str:: MaybeOwned > ) -> bool { true }
916+ fn is_str ( _: Option < & str:: MaybeOwned > ) -> bool { true }
917+ }
918+
919+ impl < ' a , Sized ? T : BytesContainer > BytesContainer for & ' a T {
920+ #[ inline]
921+ fn container_as_bytes ( & self ) -> & [ u8 ] {
922+ ( * * self ) . container_as_bytes ( )
923+ }
924+ #[ inline]
925+ fn container_as_str ( & self ) -> Option < & str > {
926+ ( * * self ) . container_as_str ( )
927+ }
928+ #[ inline]
929+ fn is_str ( _: Option < & & ' a T > ) -> bool { BytesContainer :: is_str ( None :: < & T > ) }
925930}
926931
927932#[ inline( always) ]
0 commit comments