diff options
| author | Jeremy Fitzhardinge <jsgf@fb.com> | 2019-04-09 13:40:21 -0700 |
|---|---|---|
| committer | Jeremy Fitzhardinge <jsgf@fb.com> | 2019-04-09 16:52:05 -0700 |
| commit | 08b0aca05e3709766fd7e0e01ec56a8511e4c46b (patch) | |
| tree | facc9bafaeabea80c96f4ce3e1173187cdecd88b /src/liballoc | |
| parent | 3750348daff89741e3153e0e120aa70a45ff5b68 (diff) | |
| download | rust-08b0aca05e3709766fd7e0e01ec56a8511e4c46b.tar.gz rust-08b0aca05e3709766fd7e0e01ec56a8511e4c46b.zip | |
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.
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/string.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index a3e2098695f..ace2b3ebf55 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2179,6 +2179,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")] |
