]> git.lizzy.rs Git - rust.git/commitdiff
impl Default for &mut str
authorkennytm <kennytm@gmail.com>
Sat, 2 Jun 2018 16:29:50 +0000 (00:29 +0800)
committerkennytm <kennytm@gmail.com>
Sat, 2 Jun 2018 16:29:50 +0000 (00:29 +0800)
src/liballoc/tests/str.rs
src/libcore/str/mod.rs

index 03d295d16e6a0776e831dd5e3741df5f35f5e0bc..75306ac82dfd5df1e0131ec2315580af534265e0 100644 (file)
@@ -1326,6 +1326,7 @@ fn t<S: Default + AsRef<str>>() {
 
     t::<&str>();
     t::<String>();
+    t::<&mut str>();
 }
 
 #[test]
index 3169893fcde142e59404e0f73e7a890d7d5f3d31..5e1a9c25a2190729b0696c65d43e50d2caba4fed 100644 (file)
@@ -3875,6 +3875,12 @@ impl<'a> Default for &'a str {
     fn default() -> &'a str { "" }
 }
 
+#[stable(feature = "default_mut_str", since = "1.28.0")]
+impl<'a> Default for &'a mut str {
+    /// Creates an empty mutable str
+    fn default() -> &'a mut str { unsafe { from_utf8_unchecked_mut(&mut []) } }
+}
+
 /// An iterator over the non-whitespace substrings of a string,
 /// separated by any amount of whitespace.
 ///