@@ -54,7 +54,7 @@ use core::ops::Add;
54
54
use core:: ops:: AddAssign ;
55
55
#[ cfg( not( no_global_oom_handling) ) ]
56
56
use core:: ops:: Bound :: { Excluded , Included , Unbounded } ;
57
- use core:: ops:: { self , Index , IndexMut , Range , RangeBounds } ;
57
+ use core:: ops:: { self , Range , RangeBounds } ;
58
58
use core:: ptr;
59
59
use core:: slice;
60
60
use core:: str:: pattern:: Pattern ;
@@ -2429,100 +2429,26 @@ impl AddAssign<&str> for String {
2429
2429
}
2430
2430
2431
2431
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2432
- impl ops:: Index < ops:: Range < usize > > for String {
2433
- type Output = str ;
2432
+ impl < I > ops:: Index < I > for String
2433
+ where
2434
+ I : slice:: SliceIndex < str > ,
2435
+ {
2436
+ type Output = I :: Output ;
2434
2437
2435
2438
#[ inline]
2436
- fn index ( & self , index : ops :: Range < usize > ) -> & str {
2437
- & self [ .. ] [ index]
2439
+ fn index ( & self , index : I ) -> & I :: Output {
2440
+ index . index ( self . as_str ( ) )
2438
2441
}
2439
2442
}
2440
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2441
- impl ops:: Index < ops:: RangeTo < usize > > for String {
2442
- type Output = str ;
2443
2443
2444
- #[ inline]
2445
- fn index ( & self , index : ops:: RangeTo < usize > ) -> & str {
2446
- & self [ ..] [ index]
2447
- }
2448
- }
2449
2444
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2450
- impl ops:: Index < ops:: RangeFrom < usize > > for String {
2451
- type Output = str ;
2452
-
2453
- #[ inline]
2454
- fn index ( & self , index : ops:: RangeFrom < usize > ) -> & str {
2455
- & self [ ..] [ index]
2456
- }
2457
- }
2458
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2459
- impl ops:: Index < ops:: RangeFull > for String {
2460
- type Output = str ;
2461
-
2462
- #[ inline]
2463
- fn index ( & self , _index : ops:: RangeFull ) -> & str {
2464
- unsafe { str:: from_utf8_unchecked ( & self . vec ) }
2465
- }
2466
- }
2467
- #[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
2468
- impl ops:: Index < ops:: RangeInclusive < usize > > for String {
2469
- type Output = str ;
2470
-
2471
- #[ inline]
2472
- fn index ( & self , index : ops:: RangeInclusive < usize > ) -> & str {
2473
- Index :: index ( & * * self , index)
2474
- }
2475
- }
2476
- #[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
2477
- impl ops:: Index < ops:: RangeToInclusive < usize > > for String {
2478
- type Output = str ;
2479
-
2480
- #[ inline]
2481
- fn index ( & self , index : ops:: RangeToInclusive < usize > ) -> & str {
2482
- Index :: index ( & * * self , index)
2483
- }
2484
- }
2485
-
2486
- #[ stable( feature = "derefmut_for_string" , since = "1.3.0" ) ]
2487
- impl ops:: IndexMut < ops:: Range < usize > > for String {
2488
- #[ inline]
2489
- fn index_mut ( & mut self , index : ops:: Range < usize > ) -> & mut str {
2490
- & mut self [ ..] [ index]
2491
- }
2492
- }
2493
- #[ stable( feature = "derefmut_for_string" , since = "1.3.0" ) ]
2494
- impl ops:: IndexMut < ops:: RangeTo < usize > > for String {
2495
- #[ inline]
2496
- fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut str {
2497
- & mut self [ ..] [ index]
2498
- }
2499
- }
2500
- #[ stable( feature = "derefmut_for_string" , since = "1.3.0" ) ]
2501
- impl ops:: IndexMut < ops:: RangeFrom < usize > > for String {
2502
- #[ inline]
2503
- fn index_mut ( & mut self , index : ops:: RangeFrom < usize > ) -> & mut str {
2504
- & mut self [ ..] [ index]
2505
- }
2506
- }
2507
- #[ stable( feature = "derefmut_for_string" , since = "1.3.0" ) ]
2508
- impl ops:: IndexMut < ops:: RangeFull > for String {
2509
- #[ inline]
2510
- fn index_mut ( & mut self , _index : ops:: RangeFull ) -> & mut str {
2511
- unsafe { str:: from_utf8_unchecked_mut ( & mut * self . vec ) }
2512
- }
2513
- }
2514
- #[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
2515
- impl ops:: IndexMut < ops:: RangeInclusive < usize > > for String {
2516
- #[ inline]
2517
- fn index_mut ( & mut self , index : ops:: RangeInclusive < usize > ) -> & mut str {
2518
- IndexMut :: index_mut ( & mut * * self , index)
2519
- }
2520
- }
2521
- #[ stable( feature = "inclusive_range" , since = "1.26.0" ) ]
2522
- impl ops:: IndexMut < ops:: RangeToInclusive < usize > > for String {
2445
+ impl < I > ops:: IndexMut < I > for String
2446
+ where
2447
+ I : slice:: SliceIndex < str > ,
2448
+ {
2523
2449
#[ inline]
2524
- fn index_mut ( & mut self , index : ops :: RangeToInclusive < usize > ) -> & mut str {
2525
- IndexMut :: index_mut ( & mut * * self , index )
2450
+ fn index_mut ( & mut self , index : I ) -> & mut I :: Output {
2451
+ index . index_mut ( self . as_mut_str ( ) )
2526
2452
}
2527
2453
}
2528
2454
0 commit comments