@@ -1923,6 +1923,34 @@ impl<'a> Add<&'a str> for String {
1923
1923
}
1924
1924
}
1925
1925
1926
+ /// Implements the `+` operator for concatenating a string and a single character.
1927
+ ///
1928
+ /// This has the same behavior as the [`String::push`] method.
1929
+ ///
1930
+ /// This consumes the `String` on the left-hand side and re-uses its buffer (growing it if
1931
+ /// necessary). This is done to avoid allocating a new `String` and copying the entire contents on
1932
+ /// every operation, which would lead to `O(n^2)` running time when building an `n`-byte string by
1933
+ /// repeated concatenation.
1934
+ ///
1935
+ /// # Examples
1936
+ ///
1937
+ /// ```
1938
+ /// let a = String::from("I ♥ ");
1939
+ /// let b = a + '🦀';
1940
+ /// // `a` is moved and can no longer be used here.
1941
+ /// assert_eq(b, "I ♥ 🦀");
1942
+ /// ```
1943
+ #[ unstable( feature = "string_plus_char" , reason = "new API" , issue="0" ) ]
1944
+ impl Add < char > for String {
1945
+ type Output = String ;
1946
+
1947
+ #[ inline]
1948
+ fn add ( mut self , c : char ) -> String {
1949
+ self . push ( c) ;
1950
+ self
1951
+ }
1952
+ }
1953
+
1926
1954
/// Implements the `+=` operator for appending to a `String`.
1927
1955
///
1928
1956
/// This has the same behavior as the [`push_str`] method.
@@ -1936,6 +1964,17 @@ impl<'a> AddAssign<&'a str> for String {
1936
1964
}
1937
1965
}
1938
1966
1967
+ /// Implements the `+=` operator for appending a single character to a `String`.
1968
+ ///
1969
+ /// This has the same behavior as the [`String::push`] method.
1970
+ #[ unstable( feature = "string_plus_char" , reason = "new API" , issue="0" ) ]
1971
+ impl AddAssign < char > for String {
1972
+ #[ inline]
1973
+ fn add_assign ( & mut self , c : char ) {
1974
+ self . push ( c) ;
1975
+ }
1976
+ }
1977
+
1939
1978
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1940
1979
impl ops:: Index < ops:: Range < usize > > for String {
1941
1980
type Output = str ;
0 commit comments