Implement DerefMut for String

`&mut str` is rarely useful, but it is for e.g.
`AsciiExt::make_ascii_lowercase`.
This commit is contained in:
Simon Sapin 2015-06-12 10:29:23 +02:00
parent 50d305e498
commit 2d34a531f4

View File

@ -989,6 +989,14 @@ impl ops::Deref for String {
}
}
#[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",