summary refs log tree commit diff
path: root/src/libstd/ffi
diff options
context:
space:
mode:
authorAaron Turon <aturon@mozilla.com>2015-03-26 13:39:23 -0700
committerAaron Turon <aturon@mozilla.com>2015-03-26 13:54:48 -0700
commite7525cf6200e5b62a4b1a2f3131f68d946fb331e (patch)
tree165561491041bb90c0b19df6c22d72f615da1251 /src/libstd/ffi
parent557d4346a26266d2eb13f6b0adf106b8873b0da1 (diff)
downloadrust-e7525cf6200e5b62a4b1a2f3131f68d946fb331e.tar.gz
rust-e7525cf6200e5b62a4b1a2f3131f68d946fb331e.zip
Revise use of conversion traits
This commit revises `path` and `os_str` to use blanket impls for `From`
on reference types. This both cuts down on the number of required impls,
and means that you can pass through e.g. `T: AsRef<OsStr>` to
`PathBuf::from` without an intermediate call to `as_ref`.

It also makes a FIXME note for later generalizing the blanket impls for
`AsRef` and `AsMut` to use `Deref`/`DerefMut`, once it is possible to do
so.
Diffstat (limited to 'src/libstd/ffi')
-rw-r--r--src/libstd/ffi/os_str.rs20
1 files changed, 3 insertions, 17 deletions
diff --git a/src/libstd/ffi/os_str.rs b/src/libstd/ffi/os_str.rs
index 5851c6e2998..24844ad0961 100644
--- a/src/libstd/ffi/os_str.rs
+++ b/src/libstd/ffi/os_str.rs
@@ -113,23 +113,9 @@ impl From<String> for OsString {
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
-impl<'a> From<&'a String> for OsString {
-    fn from(s: &'a String) -> OsString {
-        OsString { inner: Buf::from_str(s) }
-    }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<'a> From<&'a str> for OsString {
-    fn from(s: &'a str) -> OsString {
-        OsString { inner: Buf::from_str(s) }
-    }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<'a> From<&'a OsStr> for OsString {
-    fn from(s: &'a OsStr) -> OsString {
-        OsString { inner: s.inner.to_owned() }
+impl<'a, T: ?Sized + AsRef<OsStr>> From<&'a T> for OsString {
+    fn from(s: &'a T) -> OsString {
+        s.as_ref().to_os_string()
     }
 }