Skip to content

Commit a2ffec3

Browse files
authored
Rollup merge of rust-lang#59825 - jsgf:from-ref-string, r=sfackler
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.
2 parents 7158ed9 + 08b0aca commit a2ffec3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/liballoc/string.rs

+8
Original file line numberDiff line numberDiff line change
@@ -2189,6 +2189,14 @@ impl From<&str> for String {
21892189
}
21902190
}
21912191

2192+
#[stable(feature = "from_ref_string", since = "1.35.0")]
2193+
impl From<&String> for String {
2194+
#[inline]
2195+
fn from(s: &String) -> String {
2196+
s.clone()
2197+
}
2198+
}
2199+
21922200
// note: test pulls in libstd, which causes errors here
21932201
#[cfg(not(test))]
21942202
#[stable(feature = "string_from_box", since = "1.18.0")]

0 commit comments

Comments
 (0)