Skip to content

Commit

Permalink
Rollup merge of rust-lang#69661 - lopopolo:string-from-mut-str, r=sfa…
Browse files Browse the repository at this point in the history
…ckler

Implement From<&mut str> for String

I ran into this missing impl when trying to do `String::from` on the result returned from this API in the `uuid` crate:

https://docs.rs/uuid/0.8.1/uuid/adapter/struct.Hyphenated.html#method.encode_lower

I wasn't sure what to put in the stability annotation. I'd appreciate some help with that :)
  • Loading branch information
Centril authored Mar 15, 2020
2 parents d1e943f + 533784d commit cc16232
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,17 @@ impl From<&str> for String {
}
}

#[stable(feature = "from_mut_str_for_string", since = "1.44.0")]
impl From<&mut str> for String {
/// Converts a `&mut str` into a `String`.
///
/// The result is allocated on the heap.
#[inline]
fn from(s: &mut str) -> String {
s.to_owned()
}
}

#[stable(feature = "from_ref_string", since = "1.35.0")]
impl From<&String> for String {
#[inline]
Expand Down

0 comments on commit cc16232

Please sign in to comment.