mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
054c29d22c
Implement missing `AsMut<str>` for `str` Allows `&mut str` to be taken by a Generic which requires `T` such that `T: AsMut<str>`. Motivating example: ```rust impl<'i, T> From<T> for StructImmut<'i> where T: AsRef<str> + 'i, { fn from(asref: T) -> Self { let string: &str = asref.as_ref(); // ... } } impl<'i, T> From<T> for StructMut<'i> where T: AsMut<str> + 'i, { fn from(mut asmut: T) -> Self { let string: &mut str = asmut.as_mut(); // ... } } ``` The Immutable form of this structure can be constructed by `StructImmut::from(s)` where `s` may be a `&String` or a `&str`, because `AsRef<str>` is implemented for `str`. However, the mutable form of the structure can be constructed in the same way **only** with a `&mut String`, and **not** with a `&mut str`. This change does have some precedent, because as can be seen in [the Implementors](https://doc.rust-lang.org/std/convert/trait.AsMut.html#implementors), `AsMut<[T]>` is implemented for `[T]` as well as for `Vec<T>`, but `AsMut<str>` is implemented only for `String`. This would complete the symmetry. As a trait implementation, this should be immediately stable. |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
Cargo.toml |