From 2d34a531f4ef53f19b8cd512c121dd868328b649 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Fri, 12 Jun 2015 10:29:23 +0200 Subject: [PATCH] Implement DerefMut for String `&mut str` is rarely useful, but it is for e.g. `AsciiExt::make_ascii_lowercase`. --- src/libcollections/string.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index ef1d9b08b4a..491b7a6dd91 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -989,6 +989,14 @@ fn deref(&self) -> &str { } } +#[stable(feature = "derefmut_for_string", since = "1.2.0")] +impl ops::DerefMut for String { + #[inline] + fn deref_mut(&mut self) -> &mut str { + unsafe { mem::transmute(&mut self.vec[..]) } + } +} + /// Wrapper type providing a `&String` reference via `Deref`. #[unstable(feature = "collections")] #[deprecated(since = "1.2.0", -- 2.44.0