Skip to content

Commit

Permalink
Rollup merge of rust-lang#59825 - jsgf:from-ref-string, r=sfackler
Browse files Browse the repository at this point in the history
string: implement From<&String> for String

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing `&String` to an `impl Into<String>`
parameter frictionless.

Fixes rust-lang#59827.
  • Loading branch information
Centril committed May 15, 2019
2 parents 7158ed9 + 08b0aca commit 3ed9c54
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,14 @@ impl From<&str> for String {
}
}

#[stable(feature = "from_ref_string", since = "1.35.0")]
impl From<&String> for String {
#[inline]
fn from(s: &String) -> String {
s.clone()
}
}

// note: test pulls in libstd, which causes errors here
#[cfg(not(test))]
#[stable(feature = "string_from_box", since = "1.18.0")]
Expand Down

0 comments on commit 3ed9c54

Please sign in to comment.