@@ -18,6 +18,7 @@ use core::default::Default;
1818use core:: fmt;
1919use core:: mem;
2020use core:: ptr;
21+ use core:: ops;
2122// FIXME: ICE's abound if you import the `Slice` type while importing `Slice` trait
2223use core:: raw:: Slice as RawSlice ;
2324
@@ -530,7 +531,7 @@ impl String {
530531 /// assert_eq!(s.as_slice(), "abc123");
531532 /// ```
532533 #[ inline]
533- #[ stable = "function just renamed from push " ]
534+ #[ stable = "function just renamed from push_char " ]
534535 pub fn push ( & mut self , ch : char ) {
535536 let cur_len = self . len ( ) ;
536537 // This may use up to 4 bytes.
@@ -926,6 +927,28 @@ impl<S: Str> Add<S, String> for String {
926927 }
927928}
928929
930+ impl ops:: Slice < uint , str > for String {
931+ #[ inline]
932+ fn as_slice_ < ' a > ( & ' a self ) -> & ' a str {
933+ self . as_slice ( )
934+ }
935+
936+ #[ inline]
937+ fn slice_from_ < ' a > ( & ' a self , from : & uint ) -> & ' a str {
938+ self [ ] [ * from..]
939+ }
940+
941+ #[ inline]
942+ fn slice_to_ < ' a > ( & ' a self , to : & uint ) -> & ' a str {
943+ self [ ] [ ..* to]
944+ }
945+
946+ #[ inline]
947+ fn slice_ < ' a > ( & ' a self , from : & uint , to : & uint ) -> & ' a str {
948+ self [ ] [ * from..* to]
949+ }
950+ }
951+
929952/// Unsafe operations
930953#[ unstable = "waiting on raw module conventions" ]
931954pub mod raw {
@@ -1290,6 +1313,15 @@ mod tests {
12901313 #[ test] #[ should_fail] fn insert_bad1 ( ) { "" . to_string ( ) . insert ( 1 , 't' ) ; }
12911314 #[ test] #[ should_fail] fn insert_bad2 ( ) { "ệ" . to_string ( ) . insert ( 1 , 't' ) ; }
12921315
1316+ #[ test]
1317+ fn test_slicing ( ) {
1318+ let s = "foobar" . to_string ( ) ;
1319+ assert_eq ! ( "foobar" , s[ ] ) ;
1320+ assert_eq ! ( "foo" , s[ ..3 ] ) ;
1321+ assert_eq ! ( "bar" , s[ 3 ..] ) ;
1322+ assert_eq ! ( "oob" , s[ 1 ..4 ] ) ;
1323+ }
1324+
12931325 #[ bench]
12941326 fn bench_with_capacity ( b : & mut Bencher ) {
12951327 b. iter ( || {
0 commit comments