From a0e112ba52bbf90f958cf51b6fb39970c8a5c8b2 Mon Sep 17 00:00:00 2001 From: YOSHIOKA Takuma Date: Tue, 30 Apr 2019 15:52:07 +0900 Subject: [PATCH] Implement `BorrowMut` for `String` Closes rust-lang/rfcs#1282. --- src/liballoc/str.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index e5d4e1c533c7b..f66ff894ae865 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -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 @@ impl Borrow for String { } } +#[stable(feature = "string_borrow_mut", since = "1.36.0")] +impl BorrowMut 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;