File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -514,6 +514,15 @@ impl FromIterator<char> for EcoString {
514514 }
515515}
516516
517+ impl < ' a > FromIterator < & ' a str > for EcoString {
518+ #[ inline]
519+ fn from_iter < T : IntoIterator < Item = & ' a str > > ( iter : T ) -> Self {
520+ let mut buf = Self :: new ( ) ;
521+ buf. extend ( iter) ;
522+ buf
523+ }
524+ }
525+
517526impl FromIterator < Self > for EcoString {
518527 #[ inline]
519528 fn from_iter < T : IntoIterator < Item = Self > > ( iter : T ) -> Self {
@@ -534,6 +543,13 @@ impl Extend<char> for EcoString {
534543 }
535544}
536545
546+ impl < ' a > Extend < & ' a str > for EcoString {
547+ #[ inline]
548+ fn extend < T : IntoIterator < Item = & ' a str > > ( & mut self , iter : T ) {
549+ iter. into_iter ( ) . for_each ( move |s| self . push_str ( s) ) ;
550+ }
551+ }
552+
537553impl From < EcoString > for String {
538554 /// This needs to allocate to change the layout.
539555 #[ inline]
Original file line number Diff line number Diff line change @@ -473,14 +473,20 @@ fn test_str_construction() {
473473
474474 assert_eq ! ( str_from_eco_string, str_from_eco_string_ref) ;
475475 assert_eq ! ( str_from_eco_string_ref, "foo" ) ;
476+
477+ let from_string_iter: EcoString = [ "foo" , " " , "bar" ] . into_iter ( ) . collect ( ) ;
478+
479+ assert_eq ! ( from_string_iter, "foo bar" ) ;
476480}
477481
478482#[ test]
479483fn test_str_extend ( ) {
480484 let mut s = EcoString :: from ( "Hello, " ) ;
481485 s. extend ( "world!" . chars ( ) ) ;
482486
483- assert_eq ! ( s, "Hello, world!" ) ;
487+ s. extend ( [ " How " , "are " , "you" , "?" ] ) ;
488+
489+ assert_eq ! ( s, "Hello, world! How are you?" ) ;
484490}
485491
486492#[ test]
You can’t perform that action at this time.
0 commit comments