]> git.lizzy.rs Git - rust.git/commitdiff
Implement `BorrowMut<str>` for `String`
authorYOSHIOKA Takuma <lo48576@hard-wi.red>
Tue, 30 Apr 2019 06:52:07 +0000 (15:52 +0900)
committerYOSHIOKA Takuma <lo48576@hard-wi.red>
Tue, 30 Apr 2019 08:50:38 +0000 (17:50 +0900)
Closes rust-lang/rfcs#1282.

src/liballoc/str.rs

index e5d4e1c533c7b8062a74a83bb367e17bb8dc0536..f66ff894ae865c486cf48a4987602c2eaa1e7f55 100644 (file)
@@ -28,7 +28,7 @@
 // It's cleaner to just turn off the unused_imports warning than to fix them.
 #![allow(unused_imports)]
 
-use core::borrow::Borrow;
+use core::borrow::{Borrow, BorrowMut};
 use core::str::pattern::{Pattern, Searcher, ReverseSearcher, DoubleEndedSearcher};
 use core::mem;
 use core::ptr;
@@ -190,6 +190,14 @@ fn borrow(&self) -> &str {
     }
 }
 
+#[stable(feature = "string_borrow_mut", since = "1.36.0")]
+impl BorrowMut<str> for String {
+    #[inline]
+    fn borrow_mut(&mut self) -> &mut str {
+        &mut self[..]
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl ToOwned for str {
     type Owned = String;