File tree 3 files changed +39
-0
lines changed
3 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -2442,6 +2442,32 @@ impl<'a> Extend<Cow<'a, str>> for String {
2442
2442
}
2443
2443
}
2444
2444
2445
+ #[ cfg( not( no_global_oom_handling) ) ]
2446
+ #[ unstable( feature = "ascii_char" , issue = "110998" ) ]
2447
+ impl Extend < core:: ascii:: Char > for String {
2448
+ fn extend < I : IntoIterator < Item = core:: ascii:: Char > > ( & mut self , iter : I ) {
2449
+ self . vec . extend ( iter. into_iter ( ) . map ( |c| c. to_u8 ( ) ) ) ;
2450
+ }
2451
+
2452
+ #[ inline]
2453
+ fn extend_one ( & mut self , c : core:: ascii:: Char ) {
2454
+ self . vec . push ( c. to_u8 ( ) ) ;
2455
+ }
2456
+ }
2457
+
2458
+ #[ cfg( not( no_global_oom_handling) ) ]
2459
+ #[ unstable( feature = "ascii_char" , issue = "110998" ) ]
2460
+ impl < ' a > Extend < & ' a core:: ascii:: Char > for String {
2461
+ fn extend < I : IntoIterator < Item = & ' a core:: ascii:: Char > > ( & mut self , iter : I ) {
2462
+ self . extend ( iter. into_iter ( ) . cloned ( ) ) ;
2463
+ }
2464
+
2465
+ #[ inline]
2466
+ fn extend_one ( & mut self , c : & ' a core:: ascii:: Char ) {
2467
+ self . vec . push ( c. to_u8 ( ) ) ;
2468
+ }
2469
+ }
2470
+
2445
2471
/// A convenience impl that delegates to the impl for `&str`.
2446
2472
///
2447
2473
/// # Examples
Original file line number Diff line number Diff line change @@ -26,3 +26,15 @@ fn test_debug_control() {
26
26
assert_eq ! ( want, format!( "{chr:?}" ) , "byte: {byte}" ) ;
27
27
}
28
28
}
29
+
30
+ /// Tests Extend implementation for ascii::Char.
31
+ #[ test]
32
+ fn test_extend ( ) {
33
+ let mut s = String :: from ( "abc" ) ;
34
+ s. extend_one ( Char :: SmallD ) ;
35
+ assert_eq ! ( s, String :: from( "abcd" ) ) ;
36
+
37
+ let mut s = String :: from ( "abc" ) ;
38
+ s. extend ( Char :: CapitalA ..=Char :: CapitalC ) ;
39
+ assert_eq ! ( s, String :: from( "abcABC" ) ) ;
40
+ }
Original file line number Diff line number Diff line change 27
27
#![ feature( duration_constructors) ]
28
28
#![ feature( error_generic_member_access) ]
29
29
#![ feature( exact_size_is_empty) ]
30
+ #![ feature( extend_one) ]
30
31
#![ feature( extern_types) ]
31
32
#![ feature( float_minimum_maximum) ]
32
33
#![ feature( flt2dec) ]
You can’t perform that action at this time.
0 commit comments