@@ -68,6 +68,7 @@ println!("path exists: {}", path.exists());
68
68
#![ experimental]
69
69
70
70
use collections:: { Collection , MutableSeq } ;
71
+ use core:: kinds:: Sized ;
71
72
use c_str:: CString ;
72
73
use clone:: Clone ;
73
74
use fmt;
@@ -627,7 +628,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
627
628
/// ```
628
629
#[ inline]
629
630
fn push_many < T : BytesContainer > ( & mut self , paths : & [ T ] ) {
630
- let t: Option < T > = None ;
631
+ let t: Option < & T > = None ;
631
632
if BytesContainer :: is_str ( t) {
632
633
for p in paths. iter ( ) {
633
634
self . push ( p. container_as_str ( ) . unwrap ( ) )
@@ -792,14 +793,9 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
792
793
}
793
794
794
795
/// A trait that represents something bytes-like (e.g. a &[u8] or a &str)
795
- pub trait BytesContainer {
796
+ pub trait BytesContainer for Sized ? {
796
797
/// Returns a &[u8] representing the receiver
797
798
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
- }
803
799
/// Returns the receiver interpreted as a utf-8 string, if possible
804
800
#[ inline]
805
801
fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
@@ -808,7 +804,7 @@ pub trait BytesContainer {
808
804
/// Returns whether .container_as_str() is guaranteed to not fail
809
805
// FIXME (#8888): Remove unused arg once ::<for T> works
810
806
#[ inline]
811
- fn is_str ( _: Option < Self > ) -> bool { false }
807
+ fn is_str ( _: Option < & Self > ) -> bool { false }
812
808
}
813
809
814
810
/// A trait that represents the unsafe operations on GenericPaths
@@ -860,48 +856,44 @@ impl<'a, P: GenericPath> Display<'a, P> {
860
856
}
861
857
}
862
858
863
- impl < ' a > BytesContainer for & ' a str {
859
+ impl BytesContainer for str {
864
860
#[ inline]
865
- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
861
+ fn container_as_bytes ( & self ) -> & [ u8 ] {
866
862
self . as_bytes ( )
867
863
}
868
864
#[ 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 )
871
867
}
872
868
#[ inline]
873
- fn is_str ( _: Option < & ' a str > ) -> bool { true }
869
+ fn is_str ( _: Option < & str > ) -> bool { true }
874
870
}
875
871
876
872
impl BytesContainer for String {
877
873
#[ inline]
878
- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
874
+ fn container_as_bytes ( & self ) -> & [ u8 ] {
879
875
self . as_bytes ( )
880
876
}
881
877
#[ inline]
882
- fn container_as_str < ' a > ( & ' a self ) -> Option < & ' a str > {
878
+ fn container_as_str ( & self ) -> Option < & str > {
883
879
Some ( self . as_slice ( ) )
884
880
}
885
881
#[ inline]
886
- fn is_str ( _: Option < String > ) -> bool { true }
882
+ fn is_str ( _: Option < & String > ) -> bool { true }
887
883
}
888
884
889
- impl < ' a > BytesContainer for & ' a [ u8 ] {
885
+ impl BytesContainer for [ u8 ] {
890
886
#[ inline]
891
- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
892
- * self
887
+ fn container_as_bytes ( & self ) -> & [ u8 ] {
888
+ self
893
889
}
894
890
}
895
891
896
892
impl BytesContainer for Vec < u8 > {
897
893
#[ inline]
898
- fn container_as_bytes < ' a > ( & ' a self ) -> & ' a [ u8 ] {
894
+ fn container_as_bytes ( & self ) -> & [ u8 ] {
899
895
self . as_slice ( )
900
896
}
901
- #[ inline]
902
- fn container_into_owned_bytes ( self ) -> Vec < u8 > {
903
- self
904
- }
905
897
}
906
898
907
899
impl BytesContainer for CString {
@@ -921,7 +913,20 @@ impl<'a> BytesContainer for str::MaybeOwned<'a> {
921
913
Some ( self . as_slice ( ) )
922
914
}
923
915
#[ 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 > ) }
925
930
}
926
931
927
932
#[ inline( always) ]
0 commit comments