diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2015-06-12 10:29:23 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2015-07-13 16:21:43 +0200 |
| commit | 2d34a531f4ef53f19b8cd512c121dd868328b649 (patch) | |
| tree | 685d2fcb52f956465f1d4514a3e06a0546d16695 | |
| parent | 50d305e498c29c022c5bca2726d22e9f09b0a437 (diff) | |
| download | rust-2d34a531f4ef53f19b8cd512c121dd868328b649.tar.gz rust-2d34a531f4ef53f19b8cd512c121dd868328b649.zip | |
Implement DerefMut for String
`&mut str` is rarely useful, but it is for e.g. `AsciiExt::make_ascii_lowercase`.
| -rw-r--r-- | src/libcollections/string.rs | 8 |
1 files changed, 8 insertions, 0 deletions
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 @@ 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", |
