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