@@ -67,6 +67,7 @@ println!("path exists: {}", path.exists());
6767
6868#![ experimental]
6969
70+ use core:: kinds:: Sized ;
7071use c_str:: CString ;
7172use clone:: Clone ;
7273use fmt;
@@ -626,7 +627,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
626627 /// ```
627628 #[ inline]
628629 fn push_many < T : BytesContainer > ( & mut self , paths : & [ T ] ) {
629- let t: Option < T > = None ;
630+ let t: Option < & T > = None ;
630631 if BytesContainer :: is_str ( t) {
631632 for p in paths. iter ( ) {
632633 self . push ( p. container_as_str ( ) . unwrap ( ) )
@@ -791,14 +792,9 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
791792}
792793
793794/// A trait that represents something bytes-like (e.g. a &[u8] or a &str)
794- pub trait BytesContainer {
795+ pub trait BytesContainer for Sized ? {
795796 /// Returns a &[u8] representing the receiver
796797 fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] ;
797- /// Consumes the receiver and converts it into Vec<u8>
798- #[ inline]
799- fn container_into_owned_bytes ( self ) -> Vec < u8 > {
800- self . container_as_bytes ( ) . to_vec ( )
801- }
802798 /// Returns the receiver interpreted as a utf-8 string, if possible
803799 #[ inline]
804800 fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
@@ -807,7 +803,7 @@ pub trait BytesContainer {
807803 /// Returns whether .container_as_str() is guaranteed to not fail
808804 // FIXME (#8888): Remove unused arg once ::<for T> works
809805 #[ inline]
810- fn is_str ( _: Option < Self > ) -> bool { false }
806+ fn is_str ( _: Option < & Self > ) -> bool { false }
811807}
812808
813809/// A trait that represents the unsafe operations on GenericPaths
@@ -859,48 +855,44 @@ impl<'a, P: GenericPath> Display<'a, P> {
859855 }
860856}
861857
862- impl < ' a > BytesContainer for & ' a str {
858+ impl BytesContainer for str {
863859 #[ inline]
864- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
860+ fn container_as_bytes ( & self ) -> & [ u8 ] {
865861 self . as_bytes ( )
866862 }
867863 #[ inline]
868- fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
869- Some ( * self )
864+ fn container_as_str ( & self ) -> Option < & str > {
865+ Some ( self )
870866 }
871867 #[ inline]
872- fn is_str ( _: Option < & ' a str > ) -> bool { true }
868+ fn is_str ( _: Option < & str > ) -> bool { true }
873869}
874870
875871impl BytesContainer for String {
876872 #[ inline]
877- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
873+ fn container_as_bytes ( & self ) -> & [ u8 ] {
878874 self . as_bytes ( )
879875 }
880876 #[ inline]
881- fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
877+ fn container_as_str ( & self ) -> Option < & str > {
882878 Some ( self . as_slice ( ) )
883879 }
884880 #[ inline]
885- fn is_str ( _: Option < String > ) -> bool { true }
881+ fn is_str ( _: Option < & String > ) -> bool { true }
886882}
887883
888- impl < ' a > BytesContainer for & ' a [ u8 ] {
884+ impl BytesContainer for [ u8 ] {
889885 #[ inline]
890- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
891- * self
886+ fn container_as_bytes ( & self ) -> & [ u8 ] {
887+ self
892888 }
893889}
894890
895891impl BytesContainer for Vec < u8 > {
896892 #[ inline]
897- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
893+ fn container_as_bytes ( & self ) -> & [ u8 ] {
898894 self . as_slice ( )
899895 }
900- #[ inline]
901- fn container_into_owned_bytes ( self ) -> Vec < u8 > {
902- self
903- }
904896}
905897
906898impl BytesContainer for CString {
@@ -920,7 +912,20 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
920912 Some ( self . as_slice ( ) )
921913 }
922914 #[ inline]
923- fn is_str ( _: Option < str:: MaybeOwned > ) -> bool { true }
915+ fn is_str ( _: Option < & str:: MaybeOwned > ) -> bool { true }
916+ }
917+
918+ impl < ' a , Sized ? T : BytesContainer > BytesContainer for & ' a T {
919+ #[ inline]
920+ fn container_as_bytes ( & self ) -> & [ u8 ] {
921+ ( * * self ) . container_as_bytes ( )
922+ }
923+ #[ inline]
924+ fn container_as_str ( & self ) -> Option < & str > {
925+ ( * * self ) . container_as_str ( )
926+ }
927+ #[ inline]
928+ fn is_str ( _: Option < & & ' a T > ) -> bool { BytesContainer :: is_str ( None :: < & T > ) }
924929}
925930
926931#[ inline( always) ]
0 commit comments