From 1133a149f1bd89bbc9303e3514a6bc20c3a5fc8b Mon Sep 17 00:00:00 2001 From: George Burton Date: Sun, 22 Apr 2018 22:57:52 +0100 Subject: [PATCH 1/6] Implement From for more types on Cow --- src/liballoc/string.rs | 8 ++++++++ src/liballoc/vec.rs | 7 +++++++ src/libstd/ffi/c_str.rs | 24 ++++++++++++++++++++++++ src/libstd/ffi/os_str.rs | 24 ++++++++++++++++++++++++ src/libstd/path.rs | 8 ++++++++ 5 files changed, 71 insertions(+) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 2f84d5f7f8676..5f684361fdc23 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2239,6 +2239,14 @@ impl<'a> From for Cow<'a, str> { } } +#[stable(feature = "cow_from_string_ref", since = "1.28.0")] +impl<'a> From<&'a String> for Cow<'a, str> { + #[inline] + fn from(s: &'a String) -> Cow<'a, str> { + Cow::Borrowed(s.as_str()) + } +} + #[stable(feature = "cow_str_from_iter", since = "1.12.0")] impl<'a> FromIterator for Cow<'a, str> { fn from_iter>(it: I) -> Cow<'a, str> { diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index b184404c15bfd..be4c80c85d997 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2285,6 +2285,13 @@ impl<'a, T: Clone> From> for Cow<'a, [T]> { } } +#[stable(feature = "cow_from_vec_ref", since = "1.28.0")] +impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { + fn from(v: &'a Vec) -> Cow<'a, [T]> { + Cow::Borrowed(v.as_slice()) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl<'a, T> FromIterator for Cow<'a, [T]> where T: Clone { fn from_iter>(it: I) -> Cow<'a, [T]> { diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index c88c2bc913713..08a1596ef25f6 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -706,6 +706,30 @@ impl From for Box { } } +#[stable(feature = "cow_from_cstr", since = "1.28.0")] +impl<'a> From for Cow<'a, CStr> { + #[inline] + fn from(s: CString) -> Cow<'a, CStr> { + Cow::Owned(s) + } +} + +#[stable(feature = "cow_from_cstr", since = "1.28.0")] +impl<'a> From<&'a CStr> for Cow<'a, CStr> { + #[inline] + fn from(s: &'a CStr) -> Cow<'a, CStr> { + Cow::Borrowed(s) + } +} + +#[stable(feature = "cow_from_cstr", since = "1.28.0")] +impl<'a> From<&'a CString> for Cow<'a, CStr> { + #[inline] + fn from(s: &'a CString) -> Cow<'a, CStr> { + Cow::Borrowed(s.as_c_str()) + } +} + #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { #[inline] diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 4850ed0c5be05..e42a28ed88f82 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -664,6 +664,30 @@ impl<'a> From<&'a OsStr> for Rc { } } +#[stable(feature = "cow_from_osstr", since = "1.28.0")] +impl<'a> From for Cow<'a, OsStr> { + #[inline] + fn from(s: OsString) -> Cow<'a, OsStr> { + Cow::Owned(s) + } +} + +#[stable(feature = "cow_from_osstr", since = "1.28.0")] +impl<'a> From<&'a OsStr> for Cow<'a, OsStr> { + #[inline] + fn from(s: &'a OsStr) -> Cow<'a, OsStr> { + Cow::Borrowed(s) + } +} + +#[stable(feature = "cow_from_osstr", since = "1.28.0")] +impl<'a> From<&'a OsString> for Cow<'a, OsStr> { + #[inline] + fn from(s: &'a OsString) -> Cow<'a, OsStr> { + Cow::Borrowed(s.as_os_str()) + } +} + #[stable(feature = "box_default_extra", since = "1.17.0")] impl Default for Box { fn default() -> Box { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ec96157547383..19f38e4d6d9b3 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1532,6 +1532,14 @@ impl<'a> From for Cow<'a, Path> { } } +#[stable(feature = "cow_from_pathbuf_ref", since = "1.28.0")] +impl<'a> From<&'a PathBuf> for Cow<'a, Path> { + #[inline] + fn from(p: &'a PathBuf) -> Cow<'a, Path> { + Cow::Borrowed(p.as_path()) + } +} + #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { #[inline] From ea8131de53a7aa587938106cfb5b0ec77b127bca Mon Sep 17 00:00:00 2001 From: George Burton Date: Fri, 27 Apr 2018 20:27:38 +0100 Subject: [PATCH 2/6] Add cstring_from_cow_cstr and osstring_from_cow_osstr --- src/libstd/ffi/c_str.rs | 8 ++++++++ src/libstd/ffi/os_str.rs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 08a1596ef25f6..7f38cadfb22ad 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -682,6 +682,14 @@ impl Borrow for CString { fn borrow(&self) -> &CStr { self } } +#[stable(feature = "cstring_from_cow_cstr", since = "1.28.0")] +impl<'a> From> for CString { + #[inline] + fn from(s: Cow<'a, CStr>) -> Self { + s.into_owned() + } +} + #[stable(feature = "box_from_c_str", since = "1.17.0")] impl<'a> From<&'a CStr> for Box { fn from(s: &'a CStr) -> Box { diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index e42a28ed88f82..0a3148029d053 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -688,6 +688,14 @@ impl<'a> From<&'a OsString> for Cow<'a, OsStr> { } } +#[stable(feature = "osstring_from_cow_osstr", since = "1.28.0")] +impl<'a> From> for OsString { + #[inline] + fn from(s: Cow<'a, OsStr>) -> Self { + s.into_owned() + } +} + #[stable(feature = "box_default_extra", since = "1.17.0")] impl Default for Box { fn default() -> Box { From d87b039ea61b5be401f855b6ab788ddd6e04c847 Mon Sep 17 00:00:00 2001 From: George Burton Date: Fri, 27 Apr 2018 20:41:00 +0100 Subject: [PATCH 3/6] Add pathbuf_from_cow_path --- src/libstd/path.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 19f38e4d6d9b3..b7ab14b29ca37 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1540,6 +1540,14 @@ impl<'a> From<&'a PathBuf> for Cow<'a, Path> { } } +#[stable(feature = "pathbuf_from_cow_path", since = "1.28.0")] +impl<'a> From> for PathBuf { + #[inline] + fn from(p: Cow<'a, Path>) -> Self { + p.into_owned() + } +} + #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { #[inline] From f3e858aae761b30a56e8b03f510f360edeb3a2f1 Mon Sep 17 00:00:00 2001 From: George Burton Date: Fri, 27 Apr 2018 20:46:06 +0100 Subject: [PATCH 4/6] Update the stable attributes to use the current nightly version number --- src/liballoc/string.rs | 2 +- src/liballoc/vec.rs | 2 +- src/libstd/ffi/c_str.rs | 8 ++++---- src/libstd/ffi/os_str.rs | 8 ++++---- src/libstd/path.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 5f684361fdc23..61a207fc5b35c 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2239,7 +2239,7 @@ impl<'a> From for Cow<'a, str> { } } -#[stable(feature = "cow_from_string_ref", since = "1.28.0")] +#[stable(feature = "cow_from_string_ref", since = "1.27.0")] impl<'a> From<&'a String> for Cow<'a, str> { #[inline] fn from(s: &'a String) -> Cow<'a, str> { diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index be4c80c85d997..315a8a0aad07f 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2285,7 +2285,7 @@ impl<'a, T: Clone> From> for Cow<'a, [T]> { } } -#[stable(feature = "cow_from_vec_ref", since = "1.28.0")] +#[stable(feature = "cow_from_vec_ref", since = "1.27.0")] impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { fn from(v: &'a Vec) -> Cow<'a, [T]> { Cow::Borrowed(v.as_slice()) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 7f38cadfb22ad..10f59b0a3cc2c 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -682,7 +682,7 @@ impl Borrow for CString { fn borrow(&self) -> &CStr { self } } -#[stable(feature = "cstring_from_cow_cstr", since = "1.28.0")] +#[stable(feature = "cstring_from_cow_cstr", since = "1.27.0")] impl<'a> From> for CString { #[inline] fn from(s: Cow<'a, CStr>) -> Self { @@ -714,7 +714,7 @@ impl From for Box { } } -#[stable(feature = "cow_from_cstr", since = "1.28.0")] +#[stable(feature = "cow_from_cstr", since = "1.27.0")] impl<'a> From for Cow<'a, CStr> { #[inline] fn from(s: CString) -> Cow<'a, CStr> { @@ -722,7 +722,7 @@ impl<'a> From for Cow<'a, CStr> { } } -#[stable(feature = "cow_from_cstr", since = "1.28.0")] +#[stable(feature = "cow_from_cstr", since = "1.27.0")] impl<'a> From<&'a CStr> for Cow<'a, CStr> { #[inline] fn from(s: &'a CStr) -> Cow<'a, CStr> { @@ -730,7 +730,7 @@ impl<'a> From<&'a CStr> for Cow<'a, CStr> { } } -#[stable(feature = "cow_from_cstr", since = "1.28.0")] +#[stable(feature = "cow_from_cstr", since = "1.27.0")] impl<'a> From<&'a CString> for Cow<'a, CStr> { #[inline] fn from(s: &'a CString) -> Cow<'a, CStr> { diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index 0a3148029d053..d865ffa8e2f81 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -664,7 +664,7 @@ impl<'a> From<&'a OsStr> for Rc { } } -#[stable(feature = "cow_from_osstr", since = "1.28.0")] +#[stable(feature = "cow_from_osstr", since = "1.27.0")] impl<'a> From for Cow<'a, OsStr> { #[inline] fn from(s: OsString) -> Cow<'a, OsStr> { @@ -672,7 +672,7 @@ impl<'a> From for Cow<'a, OsStr> { } } -#[stable(feature = "cow_from_osstr", since = "1.28.0")] +#[stable(feature = "cow_from_osstr", since = "1.27.0")] impl<'a> From<&'a OsStr> for Cow<'a, OsStr> { #[inline] fn from(s: &'a OsStr) -> Cow<'a, OsStr> { @@ -680,7 +680,7 @@ impl<'a> From<&'a OsStr> for Cow<'a, OsStr> { } } -#[stable(feature = "cow_from_osstr", since = "1.28.0")] +#[stable(feature = "cow_from_osstr", since = "1.27.0")] impl<'a> From<&'a OsString> for Cow<'a, OsStr> { #[inline] fn from(s: &'a OsString) -> Cow<'a, OsStr> { @@ -688,7 +688,7 @@ impl<'a> From<&'a OsString> for Cow<'a, OsStr> { } } -#[stable(feature = "osstring_from_cow_osstr", since = "1.28.0")] +#[stable(feature = "osstring_from_cow_osstr", since = "1.27.0")] impl<'a> From> for OsString { #[inline] fn from(s: Cow<'a, OsStr>) -> Self { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index b7ab14b29ca37..83633210ff2cb 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1532,7 +1532,7 @@ impl<'a> From for Cow<'a, Path> { } } -#[stable(feature = "cow_from_pathbuf_ref", since = "1.28.0")] +#[stable(feature = "cow_from_pathbuf_ref", since = "1.27.0")] impl<'a> From<&'a PathBuf> for Cow<'a, Path> { #[inline] fn from(p: &'a PathBuf) -> Cow<'a, Path> { @@ -1540,7 +1540,7 @@ impl<'a> From<&'a PathBuf> for Cow<'a, Path> { } } -#[stable(feature = "pathbuf_from_cow_path", since = "1.28.0")] +#[stable(feature = "pathbuf_from_cow_path", since = "1.27.0")] impl<'a> From> for PathBuf { #[inline] fn from(p: Cow<'a, Path>) -> Self { From 17e262880c13abdc4d7bf72eb7e87146f0f3b1f0 Mon Sep 17 00:00:00 2001 From: George Burton Date: Wed, 9 May 2018 07:23:02 +0100 Subject: [PATCH 5/6] Update features to 1.28.0 --- src/liballoc/string.rs | 2 +- src/liballoc/vec.rs | 2 +- src/libstd/ffi/c_str.rs | 8 ++++---- src/libstd/ffi/os_str.rs | 8 ++++---- src/libstd/path.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 61a207fc5b35c..5f684361fdc23 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2239,7 +2239,7 @@ impl<'a> From for Cow<'a, str> { } } -#[stable(feature = "cow_from_string_ref", since = "1.27.0")] +#[stable(feature = "cow_from_string_ref", since = "1.28.0")] impl<'a> From<&'a String> for Cow<'a, str> { #[inline] fn from(s: &'a String) -> Cow<'a, str> { diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 315a8a0aad07f..be4c80c85d997 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -2285,7 +2285,7 @@ impl<'a, T: Clone> From> for Cow<'a, [T]> { } } -#[stable(feature = "cow_from_vec_ref", since = "1.27.0")] +#[stable(feature = "cow_from_vec_ref", since = "1.28.0")] impl<'a, T: Clone> From<&'a Vec> for Cow<'a, [T]> { fn from(v: &'a Vec) -> Cow<'a, [T]> { Cow::Borrowed(v.as_slice()) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 10f59b0a3cc2c..05ab4c3cecc01 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -682,7 +682,7 @@ impl Borrow for CString { fn borrow(&self) -> &CStr { self } } -#[stable(feature = "cstring_from_cow_cstr", since = "1.27.0")] +#[stable(feature = "cstring_from_cow_cstr", since = "1.2780")] impl<'a> From> for CString { #[inline] fn from(s: Cow<'a, CStr>) -> Self { @@ -714,7 +714,7 @@ impl From for Box { } } -#[stable(feature = "cow_from_cstr", since = "1.27.0")] +#[stable(feature = "cow_from_cstr", since = "1.28.0")] impl<'a> From for Cow<'a, CStr> { #[inline] fn from(s: CString) -> Cow<'a, CStr> { @@ -722,7 +722,7 @@ impl<'a> From for Cow<'a, CStr> { } } -#[stable(feature = "cow_from_cstr", since = "1.27.0")] +#[stable(feature = "cow_from_cstr", since = "1.28.0")] impl<'a> From<&'a CStr> for Cow<'a, CStr> { #[inline] fn from(s: &'a CStr) -> Cow<'a, CStr> { @@ -730,7 +730,7 @@ impl<'a> From<&'a CStr> for Cow<'a, CStr> { } } -#[stable(feature = "cow_from_cstr", since = "1.27.0")] +#[stable(feature = "cow_from_cstr", since = "1.28.0")] impl<'a> From<&'a CString> for Cow<'a, CStr> { #[inline] fn from(s: &'a CString) -> Cow<'a, CStr> { diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs index d865ffa8e2f81..0a3148029d053 100644 --- a/src/libstd/ffi/os_str.rs +++ b/src/libstd/ffi/os_str.rs @@ -664,7 +664,7 @@ impl<'a> From<&'a OsStr> for Rc { } } -#[stable(feature = "cow_from_osstr", since = "1.27.0")] +#[stable(feature = "cow_from_osstr", since = "1.28.0")] impl<'a> From for Cow<'a, OsStr> { #[inline] fn from(s: OsString) -> Cow<'a, OsStr> { @@ -672,7 +672,7 @@ impl<'a> From for Cow<'a, OsStr> { } } -#[stable(feature = "cow_from_osstr", since = "1.27.0")] +#[stable(feature = "cow_from_osstr", since = "1.28.0")] impl<'a> From<&'a OsStr> for Cow<'a, OsStr> { #[inline] fn from(s: &'a OsStr) -> Cow<'a, OsStr> { @@ -680,7 +680,7 @@ impl<'a> From<&'a OsStr> for Cow<'a, OsStr> { } } -#[stable(feature = "cow_from_osstr", since = "1.27.0")] +#[stable(feature = "cow_from_osstr", since = "1.28.0")] impl<'a> From<&'a OsString> for Cow<'a, OsStr> { #[inline] fn from(s: &'a OsString) -> Cow<'a, OsStr> { @@ -688,7 +688,7 @@ impl<'a> From<&'a OsString> for Cow<'a, OsStr> { } } -#[stable(feature = "osstring_from_cow_osstr", since = "1.27.0")] +#[stable(feature = "osstring_from_cow_osstr", since = "1.28.0")] impl<'a> From> for OsString { #[inline] fn from(s: Cow<'a, OsStr>) -> Self { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 83633210ff2cb..b7ab14b29ca37 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1532,7 +1532,7 @@ impl<'a> From for Cow<'a, Path> { } } -#[stable(feature = "cow_from_pathbuf_ref", since = "1.27.0")] +#[stable(feature = "cow_from_pathbuf_ref", since = "1.28.0")] impl<'a> From<&'a PathBuf> for Cow<'a, Path> { #[inline] fn from(p: &'a PathBuf) -> Cow<'a, Path> { @@ -1540,7 +1540,7 @@ impl<'a> From<&'a PathBuf> for Cow<'a, Path> { } } -#[stable(feature = "pathbuf_from_cow_path", since = "1.27.0")] +#[stable(feature = "pathbuf_from_cow_path", since = "1.28.0")] impl<'a> From> for PathBuf { #[inline] fn from(p: Cow<'a, Path>) -> Self { From 7c0f664f153f4f41f820723c6b2c758ad5286531 Mon Sep 17 00:00:00 2001 From: George Burton Date: Wed, 9 May 2018 07:32:50 +0100 Subject: [PATCH 6/6] Fix typo --- src/libstd/ffi/c_str.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/ffi/c_str.rs b/src/libstd/ffi/c_str.rs index 05ab4c3cecc01..7f38cadfb22ad 100644 --- a/src/libstd/ffi/c_str.rs +++ b/src/libstd/ffi/c_str.rs @@ -682,7 +682,7 @@ impl Borrow for CString { fn borrow(&self) -> &CStr { self } } -#[stable(feature = "cstring_from_cow_cstr", since = "1.2780")] +#[stable(feature = "cstring_from_cow_cstr", since = "1.28.0")] impl<'a> From> for CString { #[inline] fn from(s: Cow<'a, CStr>) -> Self {