Skip to content

Commit 4c1f5bd

Browse files
committed
convert: add Into<Cow> impls for &str and String
1 parent 9de34a8 commit 4c1f5bd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/libcollections/string.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1019,27 +1019,44 @@ impl AsRef<str> for String {
10191019

10201020
#[stable(feature = "rust1", since = "1.0.0")]
10211021
impl<'a> From<&'a str> for String {
1022+
#[inline]
10221023
fn from(s: &'a str) -> String {
10231024
s.to_string()
10241025
}
10251026
}
10261027

1028+
#[stable(feature = "rust1", since = "1.0.0")]
1029+
impl<'a> From<&'a str> for Cow<'a, str> {
1030+
#[inline]
1031+
fn from(s: &'a str) -> Cow<'a, str> {
1032+
Cow::Borrowed(s)
1033+
}
1034+
}
1035+
1036+
#[stable(feature = "rust1", since = "1.0.0")]
1037+
impl<'a> From<String> for Cow<'a, str> {
1038+
#[inline]
1039+
fn from(s: String) -> Cow<'a, str> {
1040+
Cow::Owned(s)
1041+
}
1042+
}
1043+
10271044
#[stable(feature = "rust1", since = "1.0.0")]
10281045
impl Into<Vec<u8>> for String {
10291046
fn into(self) -> Vec<u8> {
10301047
self.into_bytes()
10311048
}
10321049
}
10331050

1034-
#[stable(feature = "rust1", since = "1.0.0")]
1051+
#[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")]
10351052
impl IntoCow<'static, str> for String {
10361053
#[inline]
10371054
fn into_cow(self) -> Cow<'static, str> {
10381055
Cow::Owned(self)
10391056
}
10401057
}
10411058

1042-
#[stable(feature = "rust1", since = "1.0.0")]
1059+
#[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")]
10431060
impl<'a> IntoCow<'a, str> for &'a str {
10441061
#[inline]
10451062
fn into_cow(self) -> Cow<'a, str> {

0 commit comments

Comments
 (0)