Skip to content

Commit 08b0aca

Browse files
committed
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.
1 parent 3750348 commit 08b0aca

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
@@ -2179,6 +2179,14 @@ impl From<&str> for String {
21792179
}
21802180
}
21812181

2182+
#[stable(feature = "from_ref_string", since = "1.35.0")]
2183+
impl From<&String> for String {
2184+
#[inline]
2185+
fn from(s: &String) -> String {
2186+
s.clone()
2187+
}
2188+
}
2189+
21822190
// note: test pulls in libstd, which causes errors here
21832191
#[cfg(not(test))]
21842192
#[stable(feature = "string_from_box", since = "1.18.0")]

0 commit comments

Comments
 (0)