Skip to content

Commit

Permalink
string: implement From<&String> for String
Browse files Browse the repository at this point in the history
Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing &String to an `impl Into<String>`
parameter frictionless.
  • Loading branch information
jsgf committed Apr 9, 2019
1 parent 3750348 commit 08b0aca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/liballoc/string.rs
Expand Up @@ -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")]
Expand Down

0 comments on commit 08b0aca

Please sign in to comment.